3

I have multiple forks of a project and I need to branch from a starting point in one of those forks. I'm not certain how one can do this with "git". Basically, the situation is as follows:

  • SOURCE project
  • I forked SOURCE to MINE
  • You forked SOURCE to YOURS
  • I have MINE cloned to my LOCAL machine

Now YOURS has a branch called NEXT which I want to work on. How do I checkout YOURS/NEXT in my LOCAL clone? Ideally I will be branching form this point and pushing my changes to MINE, issues a pull request, then you merge them to YOURS.

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
  • Good question. I was surprised that this was so hard to find. The `git checkout --help` docs don't mention this use case at all. I'm surprised that more people don't have a "origin", which is production, such as your SOURCE. And, a "mine" for local development which you can test remote, clean up, and squash from. – kevinmm Dec 12 '14 at 17:44

2 Answers2

5

You need to:

  • declare a remote referring to "YOURS"
  • declare a local branch which will track YOURS/NEXT

That would be:

git remote add YOURS /url/for/YOURS/repo
git fetch YOURS
git checkout -b next YOURS/NEXT
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Assuming that the git repositories are published somewhere which you can pull from, you can add remote repositories with git remote add [name] [URL], then you're able to pull changes in from the repository you've added with git pull [name] [branch]

A working example of this would be something like

git remote add upstream git://github.com/git/git.git
git pull upstream maint
j883376
  • 1,125
  • 9
  • 18
  • I wish to checkout the branch, not pull from it. That is, I don't wish to merge any of their changes into one of my branches, I wish to create a new branch which exactly mirrors theirs. – edA-qa mort-ora-y May 06 '13 at 09:33