BenMorganIO
BenMorganIO

Reputation: 2046

How to fork a branch in Git?

Alright, so I need to fork a project, clone it, and what not. Thing is the master branch is 2000 or so commits ahead of the branch I need to be using. How do I fork a branch and not the main repo.

I forked it and I realized I had forked the master branch. I do a git pull origin 2-0-stable and there are tons of merge conflicts. Uh oh.

All I want to do is have another branch beside master that is the exact same as the one up on the repo.

Upvotes: 2

Views: 1020

Answers (1)

Harry Dobrev
Harry Dobrev

Reputation: 7706

You should checkout the other branch:

git checkout origin 2-0-stable

Git will automatically detect that you don't have a local branch with that name, but you have a remote branch with that name. It will create a local branch 2-0-stable which will be the same as origin/2-0-stable and will have tracking configured.

If you want to be in this state from the beginning you should git clone with the --branch option.

git clone --branch 2-0-stable <git url>

This will clone the repo, but will directly check out the specified branch.

Upvotes: 3

Related Questions