How to resolve git error: "Updates were rejected because the tip of your current branch is behind"
If you have already made some commits, you can do the following
git pull --rebase
This will place all your local commits on top of newly pulled changes.
BE VERY CAREFUL WITH THIS: this will probably overwrite all your present files with the files as they are at the head of the branch in the remote repo! If this happens and you didn't want it to you can UNDO THIS CHANGE with
git rebase --abort
... naturally you have to do that before doing any new commits!
I would do it this this way:
Stage all unstaged changes.
git add .
Stash the changes.
git stash save
Sync with remote.
git pull -r
Reapply the local changes.
git stash pop
or
git stash apply
I had the exact same issue on my branch(lets call it branch B) and I followed three simple steps to get make it work
- Switched to the master branch (git checkout master)
- Did a pull on the master (git pull)
- Created new branch (git branch C) - note here that we are now branching from master
- Now when you are on branch C, merge with branch B (git merge B)
- Now do a push (git push origin C) - works :)
Now you can delete branch B and then rename branch C to branch B.
Hope this helps.