Forking only a specific branch from Github repository

You can pull his branch into your local git repo, and then push it up to your GitHub hosted repo.

First, add a remote to this other users's GitHub page

git remote add other-user http://github.com/otheruser/repo

Then make a local checkout of that branch in your repo.

git checkout -b B4 other-user/B4

Finally, push that branch up to your repo hosted on GitHub.

git push origin B4:B4

Although the answer provided by @keelerm , is correct, but it may lead to some confusions because of the naming convention followed in that answer.

Let's assume the user, whose branch you want to clone has the github username Naruto. So, basically put Naruto has created a branch B4 from the official repository O that you want on your system.

  1. First, check whether you have Naruto's remote already added using git remote -v. If you see something along the lines of https://github.com/Naruto/O (fetch) and https://github.com/Naruto/O (push), you already have the remote added. Skip to step 3.

  2. In this step, we'll add the remote of Naruto's fork of O so that we can fetch all information from it. Choose any handy name that you'll use to refer to the remote. For illustration purposes, I'll use Kyuubi. Use this command: git remote add Kyuubi https://github.com/Naruto/O

  3. Now, you need to fetch the changes from Naruto's repository. Use this command: git fetch Kyuubi

  4. In this step we'll create our own branch called myB4 from Naruto's B4. Use this command: git checkout -b myB4 Naruto/B4

  5. If you need this myB4 branch to be reflected right away in your Github too, with the same name, use this command: git push origin myB4:myB4

That is it. Now you have a branch named myB4 from Naruto's forked repository O and your branch myB4 contains the same information as Naruto's B4.


Add that user's repository as a "remote repository" of your working directory:

git remote add someuser https://github.com/someuser/somerepo.git

Once you've done that, you need to fetch the changes from that user's repository. Later on, you can do that at any time, without affecting anything else in your local repo.

git fetch someuser

And branch that user's B4 into your own B5:

git checkout -b B5 someuser/B4

That is, create a new branch (-b) called B5, using someuser/B4 as the starting point.

Tags:

Git

Fork

Github