52

I am working with a bitbucket git repo I have read-only access to, so I created a fork to work on my features.

Question: How do I update my fork to include changes made to the original repo made by the owner?

On github, it seems one has to do the following, so I suspect it's a similar to this:

 $ git remote add upstream git://github.com/octocat/Spoon-Knife.git
 $ git fetch upstream
 $ git merge upstream/master

I couldn't find any information on this in the Bitbucket Documentation for forking

Giovanni Cerretani
  • 1,693
  • 1
  • 16
  • 30
franka
  • 1,867
  • 3
  • 17
  • 31

7 Answers7

64

Just like GitHub, you have to pull the commits down to your own machine, merge, and then push them back to your fork on Bitbucket.

If you go to your fork on Bitbucket you can click "compare fork" to get to a page where you see incoming and outgoing commits. If you go to the "incoming" tab, you will see instructions like

$ git remote add <remote_name> git@bitbucket.org:<upstream>/<repo>.git
$ git fetch <remote_name>
$ git checkout master
$ git merge <remote_name>/master

which correspond closely to the GitHub instructions.

Josh
  • 2,142
  • 2
  • 23
  • 20
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • Regarding the `merge` command, I have to use it without the leading `remotes/` – dragoon Jun 30 '12 at 09:28
  • What does the `git checkout master` achieve here? Can it be done as step 1 or 2 or 3 since it only effects the local repo? – Sanchit Jun 12 '13 at 05:02
  • For me the `git remote add` needs to be without specifying the protocol `ssh://`. Just use `git@bitbucket.org:/.git – ali Nov 18 '13 at 21:15
17
  1. Goto your fork on bitbucket
  2. Click the Branches menu from the left navigation pane
  3. Click on the "..." button to the right of the branch and select "Compare". Or, in the url add the word “compare”. So that the URL looks like this: https://bitbucket.org/<user name>/<fork name>/branches/compare
  4. Click on the switch icon (black up/down arrows between the branch segments) so that the blue arrow is pointing into your fork
  5. Select the correct branches in your fork and the owner's repo
  6. Click Compare
  7. Click Merge
Josh
  • 2,142
  • 2
  • 23
  • 20
soch guru
  • 191
  • 1
  • 3
5

Ahhhhhh here comes the easiest way....
1. Go to your fork repo.
2. Select Repository Settings tab.
3. Select Fork Syncing tab.
4. Deselect automatic sync.
5. Re-select automatic sync.

Life just got easy with this hack.

Vinod Kumar
  • 562
  • 5
  • 12
3

On the left hand side, the repository details panels shows a SYNC button IF AND ONLY IF there is any commit behind

enter image description here

  • 1
    That....forking button only appears if there is any newer commits and this is not written on any documentation. That's not very intuitive. – mcy Aug 03 '21 at 07:53
  • In Atlassian softwares is nothing intuitive. This button should be on very top of the UI appear. Seem like the devs wanted this to hide from customers :) – lortschi Feb 21 '23 at 08:42
2

In the latest version there is a Repository-Details box on the right side with a sync button if the root has unmerged updates.

Andreas
  • 1,691
  • 1
  • 15
  • 34
1

On Repository settings -> Fork Syncing Uncheck & check option "Enable fork syncing"

You will see a message Last automatic synchronization: a moment ago

0

In Bitbucket, using the "Enable Fork Syncing" feature for your forked repo makes it super easy to pull new changes from the original repo into the forked repo.

e.g.

  1. There is an original repo, and you create a forked repo. While creating a fork on the bitbucket website, there is a check box for "Enable Fork Syncing", please check it.
  2. Next, clone the forked repo into your local and create a feature branch from the master branch.
(master) $ git checkout -b feature
  1. Anytime you want to pull new commits from the original repo into the master branch, run the below commands:
# below git command will fetch all the changes from the original repo's master branch 
# into your local's master branch because we had enabled fork syncing.
(feature) $ git fetch origin master:master

# use merge or rebase as per your preference
(feature) $ git rebase master

Documentation @ https://confluence.atlassian.com/bitbucketserver/keeping-forks-synchronized-776639961.html

Jay K
  • 23
  • 1
  • 6