Publish Local Repository To Github Using Https

Please Follow below steps to push local repository to github. ### Step#1. Create new empty repository on github Please make sure you do not select Initialize this repository with a README checkbox. This is to ensure we dont get error while pushing local changes to github ### Step#2. Create local repository. ```bash echo "# any comment you want to add" >> git init git add . git commit -m "first commit" git branch -M main git remote add origin git push -u origin main ``` Starting October 1, all new GitHub repositories will create a default branch named main, and GitHub will no longer create a master branch for you. **What if I had added file while creating repository.** In this case, you will get following error ```bash To ! [rejected] main -> main (fetch first) error: failed to push some refs to '' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. ``` To override github repository you can use `--force` parameter ```bash git push origin main --force ```

This post is written by Pravin

Tags : Git

Share it :      

Leave a comment




  1. GitHub
Ad below