I cloned a Git repository, which contains about five branches. However, when I do git branch
I only see one of them:
$ git branch
* master
I know that I can do git branch -a
to see all the branches, but how would I pull all the branches locally so when I do git branch
, it shows the following?
$ git branch
* master
* staging
* etc...
I believe you have clone the repository by
now go to that folder using cd
if you type
git status
you can see all
to see all hidden branch type
it will list all the remote branch
now if you want to checkout on any particular branch just type
Use
git fetch && git checkout RemoteBranchName
.It works very well for me...
This assumes all branches are tracked.
If they aren't you can fire this in Bash:
Then run the command.
Make sure all the remote branches are fetchable in
.git/config
file.In this example, only the
origin/production
branch is fetchable, even if you try to dogit fetch --all
nothing will happen but fetching theproduction
branch:This line should be replaced by:
Then run
git fetch
etc...I usually use nothing else but commands like this:
A little shorter version:
Here's a Perl version of the one-liner provided in the accepted answer:
git branch -r | perl -e 'while(<>) {chop; my $remote = $_; my ($local) = ($remote =~ /origin\/(.*)/); print "git branch --track $local $remote\n";}' > some-output-file
You can run the output file as a Shell script if you'd like.
We deleted our Stash project repository by accident. Fortunately someone had created a fork right before the accidental loss. I cloned the fork to my local (will omit the details of how I did that). Once I had the fork fully in my local, I ran one one-liner. I modified the remote's URL (origin in my case) to point to the target repository we were recovering to:
git remote set-url origin <remote-url>
And finally pushed all branches to origin like so:
git push --all origin
and we were back in business.