The git "Updates were rejected because the tip of your current branch is behind" error happens when the branch you are pushing to has changes made it to that are not in your branch. To solve the error, run the git pull
command.
You might see an error that looks like this in the terminal when you try to push your git branch.
Pushing to [email protected]:example-project/example-repo.git
To [email protected]:example-project/example-repo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:test-project/test-repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Open your terminal and run the following command to pull changes from the remote branch.
git pull
git push
# Push to a specified branch
git push origin RemoteBranch
If this doesn't work, pull changes from the remote branch and do a rebase. Run these commands in the terminal.
git pull --rebase
git push
# Push to a specified branch
git push origin RemoteBranch
If the push does not work, try forcing the push, which may be necessary because of the rebase.
git push -f
# Push to a specified branch
git push -f origin RemoteBranch
If this doesn't work, you can overwrite the changes in your local branch with the changes from the remote branch.
Run the following command in your terminal.
git reset --hard origin/example-branch
The git "Updates were rejected because the tip of your current branch is behind" error happens when the branch you are pushing to has changes made it to that are not in your branch. To solve the error, run the git pull
command.