Skip to content

Instantly share code, notes, and snippets.

@dalehenrich
Created April 30, 2012 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalehenrich/2560506 to your computer and use it in GitHub Desktop.
Save dalehenrich/2560506 to your computer and use it in GitHub Desktop.
merge and preserve branches from a forked repository

Basic procedure gleaned from Git: Merging from Remote Branch.

  1. Start with a clone of the repository into which you want to merge the branched:
git clone https://github.com/svenvc/ston.git
*Note: you'll probably want to use a writable version of the repository url. Also at any time you can destroy the clone and start over ... of course you will lose work, but if you think that there's something wrong destroy the repository before pushing a mistake up to github ... github is the repository of record.*
  1. Add a remote reference to the repository from which you want to merge:
git remote add dale https://github.com/dalehenrich/ston.git
  1. download objects from remote repo:
git fetch dale
In this case we've got 4 branches:
From https://github.com/dalehenrich/ston
 * [new branch]      amber      -> dale/amber
 * [new branch]      gemstone   -> dale/gemstone
 * [new branch]      master     -> dale/master
 * [new branch]      pharo      -> dale/pharo
We want to merge each branch into a branch with same name in our own repo. Also we haven't made any changes to our repository since the fork was created so at this point in time we don't expect any conflicts ...
  1. Checkout and merge the master branch:
git checkout master
git merge --no-commit --no-ff dale/master
*Note: using `--no-commit --no-ff` to avoid an immediate commit after merge completes ... this gives us a chance to test the merged code or review the changes before performing the commit.*
  1. Take a look at the changes that were merged:
git status
*Note: that at any time you can execute `git revert --hard` and everything that has been done since the last commit is dropped on the floor. I use this command if I've done a merge (using `--no-commit --no-ff`) and don't like the results for some reason.*
  1. Commit the merge:
git commit -a
*Note: when you commit with the above command you'll be popped into an editor where you have the chance to add any additional comments about the merge.*
  1. The gemstone branch started at commit 74b7d1e50e4a77bc72994f4f185abdfc46acc779. I looked at my network graph for reference. Checkout and create the gemstone branch, merge the gemstone branch from dale and commit:
git checkout -b gemstone 74b7d1e50e4a77bc72994f4f185abdfc46acc779
git merge --no-commit --no-ff dale/gemstone
git status
git commit -a
  1. The pharo branch was rooted in commit 103ca12971f2b7cfe05909f40653808a3a1c9a64:
git checkout -b pharo 103ca12971f2b7cfe05909f40653808a3a1c9a64
git merge --no-commit --no-ff dale/pharo
git status
git commit -a
  1. The amber branch was rooted in commit c6023570b0d86e893fff87e41fa39c247e55a348:
git checkout -b amber c6023570b0d86e893fff87e41fa39c247e55a348
git merge --no-commit --no-ff dale/amber
git status
git commit -a
  1. Now push your results up to github:
git checkout master
git push origin master
git checkout gemstone
git push origin gemstone
git checkout pharo
git push origin pharo
git checkout amber
git push origin amber
Your network view for ston should look like the network view for [ston-example][6], the sample project that I created after cloning the **ston** project and going through all of the above steps.
  1. After you're done pushing, I'll merge my repo with yours ... moving forward pull requests can be used for specific bugfixes etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment