. Advertisement .
..3..
. Advertisement .
..4..
One day, you are proceeding with your program as usual. And suddenly, the message “Updates were rejected because the tip of your current branch is behind’‘, rendering you confused and uncertain. No worry: ITtutoria is here to help!
What Causes This Error?
Git deals with remote and local branches.
A local branch resides within your existing version of git repositories. Meanwhile, remote ones are prevalent in remote locations (major repositories often have one remote named origin).
Remote is a position where the system hosts the git repository (example: GitHub/GitLab/BitBucket/self-hosted). It helps you share or collaborate with other workers in one branch.
Thus, the error “the tip of your current branch is behind.” implies that some changes have occurred to your remote branch, one you do not have local possession.
Two types of changes are common: someone either adds the commits or adjusts that branch’s history (often via rebasing). Assess which one you encounter to choose accordant solutions.
How to Fix The Error “Updates Were Rejected Because The Tip of Your Current Branch is Behind”
Let’s approach this issue with specific examples. Look at these codes:
$ git push -u origin main
To github.com:mellamonaranja/PrefixSpan.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to '[email protected]:mellamonaranja/PrefixSpan.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
Can you guess why the error happens here? First, the remote origin already exists. Second, the commits differ between the local tree and remote origin. And as we already established in the previous section, some changes occur in your remote branch, which you have no local possessions.
$ git status
On branch main
Your branch and 'origin/main' have diverged,
and have 3 and 12 different commits each, respectively.#<<<<<<
(use "git pull" to merge the remote branch into yours)
That’s why you receive such error messages. The system wants you to merge the remote and local.
Now, remove the git.
$ rm -rf .git/
Once done, push again.
$ echo "# docker-compose_jupyternotebook" >> README.md
$ git init
Initialized empty Git repository in /Users/joohyunyoon/Documents/Workspace/.git/
$ git status
On branch master
$ git add .
$ git commit -m "edit files"
[master (root-commit) 8aef74f] edit files
6 files changed, 505 insertions(+)
...
$ git remote add origin [email protected]:mellamonaranja/docker-compose_jupyternotebook.git
$ git status
On branch master
nothing to commit, working tree clean
$ git push origin master
Counting objects: 9, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 4.59 KiB | 4.59 MiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
To github.com:mellamonaranja/docker-compose_jupyternotebook.git
* [new branch] master -> master
Conclusion
This article has instructed you to fix the error “Updates were rejected because the tip of your current branch is behind” with detailed explanations accompanying examples. Other approaches involve the cloning of CK-git repositories, which, in some cases, might send back this error: “Please make sure you have the correct access rights and the repository exists”. If this situation applies to you, navigate to ITtutoria QA sections for solutions!
Leave a comment