How do I syncronize changes from a parent repository?

I forked a repository for an open source project, and I made some changes to the project in my forked repository. Now, the people in charge of this project have released version 1.2. How do I syncronize the new code into my forked repository?

4 answers

Joshua Kramer
> How do I [synchronize new code, from the remote from which I forked] into my forked repository?

The `git`-ish way to ask this question is, how do I merge from a remote? For the long answer (and much more detail) look here at "the git book," an excellent free reference. One short answer follows; as is usually the case with `git`, TMTOWTDI, and there are definitely even shorter but less safe ways to do this.

1. Determine the name of the *remote branch* from which you want to merge (e.g., via its web UI). It will probably be `master`, but for clarity I'll call it `remote_branch`.
2. Determine your local git's name for the *remote repository* with `git remote -v`. By default, it will be `origin`, so I'll use that.
3. Create a local tracking branch with `git checkout --track origin/remote_branch` (remembering to change names as necessary). If you already have a local tracking branch, git will tell you, so don't worry.
4. Update the local tracking branch by doing `git fetch origin`, which updates your local repo regarding the state of the remote repo.
5. "Get into" the local branch into which you want the remote code to merge--i.e., your work branch, *not* your local tracking branch. For clarity I'll call that `local_branch` (though it's probably actually called `master`); to "get into" it, do `git checkout local_branch`. (Note that you may already be working there, but no harm will be done if you're already there--git will just tell you you're there.)
6. Merge your local tracking branch into your local work branch with `git merge origin/remote_branch`.

Note that in future (provided nothing changes, and that you remember the relevant names) you'll only need to do steps 4-6.

Thanks for helping, Tom. I think I wasn't clear in my description of what I did. When you say, "One updates from a repo, not a branch", I actually did update from the pgs-openscg remote; specifically, the master branch on that remote. When I did this, it put the code in the tracking branch (pgs-openscg/master) and then I merged from that branch into my own master. This merge appears to have worked. What is not working is trying to sync my own master to my Bitbucket repository.

OK, so this halfway worked. What I have is as follows:

openscg/pgstudio (Not mine, this is the original project)
joshuapk/pgstudio (which is a fork of of openscg/pgstudio, remote name is origin)

I did the following:
1. Add openscg/pgstudio (named pgs-openscg) as a remote to my local git repository.
2. did 'git remote update' to pull in the code from openscg/pgstudio
3. did 'git merge pgs-openscg/master' in my working branch. Lots of files were updated.

After step 3, nothing happened. I did a 'git commit -a', and the files that were added/changed by the merge were not comitted. I then did 'git push origin', which I expected would push all of the files changed with the merge, back up to joshuapk/pgstudio. It did not do this... in fact, if you look at the commit logs on joshuapk/pgstudio, you don't see any of the changes that were introduced by the merge.

What am I missing?

Joshua Kramer
> this halfway worked

No: what *you* did halfway worked :-) What you did is rather different from what I suggested.

> 1. Add openscg/pgstudio (named pgs-openscg) as a remote

What do you get when you do `git remote -v show pgs-openscg` ? Here's what I get on a local git:

me@it:~/path/to/a/wiki $ git remote -v show bbh
* remote bbh
Fetch URL: [ URL omitted, since it causes the answers.atlassian.comeditor to hose all following text! ]
Push URL: [ ditto ]
HEAD branch: master
Remote branch:
master tracked
Local ref configured for 'git push':
master pushes to master (up to date)

Joshua Kramer
> 2. did 'git remote update' to pull in the code from openscg/pgstudio

2 notes:

  1. One updates from a repo, not a branch.
  2. It's always more efficient, and usually safer, to be explicit about the remote repo you're updating.

Joshua Kramer
> 3. did 'git merge pgs-openscg/master' in my working branch.

3 questions:

  1. Weren't you using `pgs-openscg` as a branch name?
  2. What do you get when you do `git branch` ?
  3. What do you get when you do `git status` ?

Thanks for helping, Tom. I think I wasn't clear in my description of what I did. When you say, "One updates from a repo, not a branch", I actually did update from the pgs-openscg remote; specifically, the master branch on that remote. When I did this, it put the code in the tracking branch (pgs-openscg/master) and then I merged from that branch into my own master. This merge appears to have worked. What is not working is trying to sync my own master to my Bitbucket repository.

Something must have been wrong with the local repository. I repeated the steps exactly as I outlined them (not the steps Tom suggested) and now it seems to work.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

217 views 3 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you