I am a new user of Git. I have forked a repository called Spoon-Knife (available for practicing forking with Git). Then, I cloned it locally by running
git c
just follow three steps, git branch problem will be solved.
git remote update
git fetch
git checkout --track origin/test-branch
When I run
git branch
, it only shows*master
, not the remaining two branches.
git branch
doesn't list test_branch
, because no such local branch exist in your local repo, yet. When cloning a repo, only one local branch (master
, here) is created and checked out in the resulting clone, irrespective of the number of branches that exist in the remote repo that you cloned from. At this stage, test_branch
only exist in your repo as a remote-tracking branch, not as a local branch.
And when I run
git checkout test-branch
I get the following error [...]
You must be using an "old" version of Git. In more recent versions (from v1.7.0-rc0 onwards),
If
<branch>
is not found but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat [git checkout <branch>
] as equivalent to$ git checkout -b <branch> --track <remote>/<branch>
Simply run
git checkout -b test_branch --track origin/test_branch
instead. Or update to a more recent version of Git.
I got this error because the instruction on the Web was
git checkout https://github.com/veripool/verilog-mode
which I did in a directory where (on my own initiative) i had run git init
.
The correct Web instruction (for newbies like me) should have been
git clone https://github.com/veripool/verilog-mode
You can also get this error with any version of git if the remote branch was created after your last clone/fetch and your local repo doesn't know about it yet. I solved it by doing a git fetch
first which "tells" your local repo about all the remote branches.
git fetch
git checkout test-branch
Following worked for me
git pull
Then checkout the required branch