Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github: this branch is N commits behind

Tags:

git

github

I forked another repo and made some changes, all on directly on the github site... I have no need to fetch a local copy (it's too big to fit onto my space-limited IDE) so I want to keep all actions done directly on the github repo page (there are unlikely to be many changes required, and if so they will be insignificant and easy to do via the github webpage).

Those changes have been merged by the owner of the other repo, so that our two repos are now synchronised. However, my fork is now showing:

This branch is 4 commits behind OtherOne:master.

How do I fix things (purely via the github page) to get things to a state where my repo is not showing as being behind theirs? If I do a Compare in my repo it says:

There isn’t anything to compare.
OtherOne:master is up to date with all commits from MyOne:master.  Try switching the base for your comparison.

So I think that the repos are in fact now fully synchronised... but I just want to remove that "behind" message (because I'm like that). Is there any way? I could just delete my repo and re-fork... but that seems inelegant.

And in future, if the other repo is updated, how do I pull those changes into mine... again... all on github and not via the CLI.

like image 591
drmrbrewer Avatar asked Feb 13 '18 11:02

drmrbrewer


People also ask

How do you fix the source branch is commits behind the target branch?

It means your copy of the remote master branch (typically denoted as origin/master) has n commits more than your local version of the master branch. You can resolve this, while you have master checked out, by typing: git merge origin/master.

What does it mean to be commits behind Main?

This means every locally created branch is behind. Before preceding, you have to commit or stash all the changes you made on the branch behind commits. Solution: Checkout your local Master branch git checkout master.

How do you fix updates were rejected because the tip of your current branch is behind its remote counterpart?

The updates were rejected because the tip of your current branch is behind error can be fixed by pushing to a remote branch. This process is called a Git push, and it debugs the errors of the current branch, which is also known as a local branch.


2 Answers

Don't try it with the github site (it's possible but a bad idea). Instead use the "clean" way and do this from inside the dir with your git-repo:

  1. Tell your repository about the original one:

    git remote add upstream git://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

  2. Get the original branches: git fetch upstream

  3. Pull in the original data in to your branch: git pull upstream master

  4. Push this to your github repository: git push

like image 133
Garo Avatar answered Sep 21 '22 16:09

Garo


Update: you can now perform this action via the GitHub frontend's Fetch Upstream button - see the Release Notes here:

You can now use the web UI to synchronize an out of date branch of a fork with its upstream branch. If there are no merge conflicts between the branches, the fork's branch is updated either by fast-forwarding or by merging from the upstream's branch. If there are conflicts, you will be prompted to open a pull request to resolve.

GitHub Fetch Upstream functionality

Old Answer:

Create a pull request that merges OtherOne:master into your forked repo, then merge it. That should remove the message and ensure that the two repos are indeed synchronized.

like image 22
Adil B Avatar answered Sep 24 '22 16:09

Adil B