4

Scenario:

  • On the github exists the user "guru" and his primamy repository for the project called "bigsw". This primary repo has several branches. ("rel1", "rel2", "master")
  • this project has 2 forks made by user1 and user2.
  • Each of the abobe forks has the same branches as the primary repo, plus one different branch what contains their particular work. So, user1 forked the bigsw and created a branch called "utf8" and user2 created a branch "mongo".

  • now i want join to the project, and for my work I need the following branches:

    • guru/bigsw:master
    • user1/bigsw:utf8 (read as: USER/REPO:BRANCH)
    • user2/bigsw:mongo

What should be the recommended workflow?

My idea is:

  1. fork the guru/bisgw on the github (so will get myname/bigsw)
  2. git clone git://github.com/myname/bigsw (get a local copy)

  3. want keep synced local copy of user1/bigsw:utf8 branch and similarly want a copy of branch "mongo from user2's fork. So, I don't need clone the full repo from user1 and user2 only one branch from each. Somewhat like:

    • git remote add user1 [email protected]:user1/bigsw.git
    • git fetch user1
    • git checkout -b utf8 user1/utf8
    • and similarly for user2's mongo repo (i'm not sure with the first two commands)

  4. git checkout -b i18n (to create MY own branch - where I will make my changes)
  5. edit the sources (and i hoping than after the previous command they will automatically "going" into "i18n" branch)
  6. git push origin i18n (to push my changes to github to myname/bigsw:i18n branch)
  7. and sometime in the future will submit an pull request for my i18n branch /don't know how, but don't need it yet ;)/

Is the above an correct workflow? If yes, questions:

  • how to clone user1's branch "utf8" and user2's "mongo" branches into my local machine - Are the commands in 3.) correct?
  • how to keep in sync all (so i want in my local machine synced branches from all above) - my changes will be only in my branch "i18n".

I'm total newbie for git/github - and unfortunately need start with this complicated model(at least for me). I learned something digging into https://help.github.com/ , but not understand all "git philosophy".

I was already read:

but still wandering in the dark... :(

1 Answer 1

2

Generally nice, but I have a few suggestions.

I would leave out the git checkout -b userX userX/branch calls. Instead I would make sure I'm in the original branch by guru and create a local branch where you merge the two remotes together like this:

git checkout -b utf8-mongo
git merge user1/utf8
git merge user2/mongo

You will probably face merge conflicts which may look scary on the first sight, but you'll evenutally find your way through them (look up guides on how to resolve merge conflicts and have talkback with the authors if unsure which change to prioritize).

Then you can create your own branch off that using:

git checkout -b i18n

just as you suspected. Do your changes and obey to the rule commit early, commit often. Whenever you want to pull in changes from all the upstream branches, you do the following:

git checkout utf8-mongo
git pull guru/master
git pull user1/utf8
git pull user2/mongo

Resolve any merge conflicts you have there like above, and then switch back into your branch and get the new changes:

git checkout i18n
git merge utf8-mongo

The rationale behind splitting the branches is that merge conflicts are ugly to manage and you might in the future discard your branch and start from scratch. In that case you would not want to do all the merging of the others branches again, so you save them in a separate one.

When doing a pull request using githubs web interface, you only request to pull from your branch i18n. People (i.e. guru) might be unhappy though as you pulled in a lot of other peoples branches, which may not be ripe enough yet to be merged into his own branch. You may need to have some mail contact to coordinate that pull. The best is probably to have a healthy communication with the devs right from the start.

2
  • Great Tip! This answers improves my understanding of mystic Git a bit more. Commented Jun 18, 2012 at 3:52
  • @vincentmathew Thank you! Glad that I could help. Commented Jun 18, 2012 at 7:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.