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
git remote add origin https://yourBitbucketLink
git fetch origin
git checkout -b yourNewLocalBranchName origin/requiredRemoteBranch (use tab :D)
Now locally your yourNewLocalBranchName
is your requiredRemoteBranch
.
I believe you have cloned the repository by:
git clone https://github.com/pathOfrepository
Now go to that folder using cd:
cd pathOfrepository
If you type git status
you can see all:
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
To see all hidden branch types:
git branch -a
It will list all the remote branchs.
Now if you want to checkout on any particular branch just type:
git checkout -b localBranchName origin/RemteBranchName
Have tried many ways, only this one is simple and works for me.
for branch in $(git ls-remote -h git@<your_repository>.git | awk '{print $2}' | sed 's:refs/heads/::')
do
git checkout "$branch"
git pull
done
If you do:
git fetch origin
then they will be all there locally. If you then perform:
git branch -a
you'll see them listed as remotes/origin/branch-name. Since they are there locally you can do whatever you please with them. For example:
git diff origin/branch-name
or
git merge origin/branch-name
or
git checkout -b some-branch origin/branch-name
After you clone the master repository, you just can execute
git fetch && git checkout <branchname>
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 do git fetch --all
nothing will happen but fetching the production
branch:
[origin]
fetch = +refs/heads/production:refs/remotes/origin/production
This line should be replaced by:
[origin]
fetch = +refs/heads/*:refs/remotes/origin/*
Then run git fetch
etc...