GIT clone a branch

Posted under » Version Control on 3 May 2021

When you clone a project

$ git clone git@github.com:anoneh/dblog.git

This gives us access to all branches in this repository and you can easily toggle between each to see each version and its files.

$ git branch -a

When you clone a repository, you pull data from a repository on the internet or an internal server known as the remote (the URL that points you to the repository on the internet).

The word origin is an alias created by your Git to replace the remote URL (you can change or specify another alias if you want).

When you clone master onto your machine, remotes/origin/master is the original master branch on the internet, and master is on your local machine. So you will pull/push from and to the remotes/origin/master.

$ git remote show origin
---
Fetch URL: git@github.com:anoneh/dblog.git
Push  URL: git@github.com:anoneh/dblog.git
HEAD branch: main
Remote branches:
  development      tracked
  main             tracked
Local branch configured for 'git pull':
  main merges with remote main
Local ref configured for 'git push':
  main pushes to main (up to date)

To clone a specific branch which is useful when you want to save space.

$ git clone --branch development --single-branch git@github.com:anoneh/dblog.git

You can check which branch you are currently on by git status

$ git status
On branch vbox

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS