I have a repository on Github with 2 branches: master
and develop
.
When I clone the repository and run $ git branch
it shows only the master
branch.
If I run $ git branch -a
I can see all the remote branches.
Now, if I do a $ git checkout develop
, I get the message:
Branch develop set up to track remote branch develop from origin.
Switched to a new branch 'develop'
What actually happened? Were the commits from the remote develop
branch fetched when I ran $ git clone remote-url
, or when I ran: $ git checkout develop
, or neither?
Have I to do a $ git pull origin develop
after checking out develop
, or it's already done?
Please help me understand how clone
works when there are multiple branches on remote.
git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.
When you clone a repository, you copy the repository from GitHub.com to your local machine. Cloning a repository pulls down a full copy of all the repository data that GitHub.com has at that point in time, including all versions of every file and folder for the project.
When you ask for a project, you clone it locally on to your machine. In other words, Git copies all the project files to your hard drive, then allows you to work on the project autonomously. All operations run locally on your machine.
To put it simply, git clone repository-url
does the following things, in order:
Creates a new empty repository.
git init
Creates a remote called "origin" and sets it to the given url.
git remote add origin repository-url
Fetches all commits and remote branches from the remote called "origin".
git fetch --all
Creates a local branch "master" to track the remote branch "origin/master".
git checkout --track origin/master
An interesting point is that a fork (in GitHub or Bitbucket) is just a server side clone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With