Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After Git clone from GitHub, I do not see my branch

Tags:

git

github

I have a repository on GitHub. It contains master and one branch.

When I clone it, I obtain only master and do not see my branch.

Why is it so? How can I see all branches in the repository?

like image 889
Anton Avatar asked Oct 22 '10 17:10

Anton


People also ask

How do I know if my branch is cloned?

You successfully cloned a Git repository into a specific folder on your server. In this case, you cloned the master branch from your Git remote repository. You can check the current branch cloned by running the “git branch” command.

Why git branch is not showing all branches?

This can happen if your repo has 0 commits. If you make a commit, your current branch will appear when you do: git branch . Show activity on this post. Sounds like you have a permission issue.

Does git clone create a branch?

The Git clone command will create a new local directory for the repository, copy all the contents of the specified repository, create the remote tracked branches, and checkout an initial branch locally. By default, Git clone will create a reference to the remote repository called origin .

Does git clone bring all branches?

The idea is to use the git-clone to clone the repository. This will automatically fetch all the branches and tags in the cloned repository. To check out the specific branch, you can use the git-checkout command to create a local tracking branch.


2 Answers

By default, git clone creates only one branch: the currently checked out one, generally master. However, it does create remote tracking branches for all other branches in the remote. Think of these as local copies of the remote's branches, which can be updated by fetching. They're not real local branches, as they're intended only as pointers to where the remote's branches are, not for you to work on.

If you run git branch -a you'll see all branches, local and remote. If you want to see just the remote ones, use git branch -r. If you prefer a visual history display, try gitk --all (or gitk --remotes).

To create a local branch to work on, use

git branch <branch-name> origin/<branch-name> 

That'll create a new local branch using the remote's branch as the starting point.

like image 187
Cascabel Avatar answered Oct 09 '22 21:10

Cascabel


You can directly do:

git checkout <original-remote-branch-name> 

This automatically creates a local branch which tracks the remote branch with the same name. Do this always after cloning, if you want to work on a particular branch other than master.

Note: When you clone the remote name is by default 'origin' which is different from the remote name used in other machines where you are developing. So, you can initially name your remote before cloning or push to origin ever after.

like image 25
Arun Reddy Avatar answered Oct 09 '22 19:10

Arun Reddy