Cheatsheet: Git Branching with a Git Server

Posted on In Linux, Programming, Tutorial

It is common to set up git servers to host git repositories. Branching is lightweight in git and a very friendly mechanism to manage code. Here, I summarize a cheatsheet of common git branching commands for working on repositories from a git server. This post assumes that you have basic knowledge with git. If you are not familiar with git, you may want check https://www.systutorials.com/howto-for-new-git-user/ first.

Clone a repository

$ git clone git://example.com/your/repo.git

List all local branches

$ git branch -a

Update all branches

$ git pull

Change to a branch

$ git checkout rc

Create and push a new branch

$ git branch dev-b1
$ git checkout dev-b1
$ git push origin dev-b1

Create a branch and immediately check it out

$ git checkout -b dev-b1

Push changes at a certain branch

$ git push origin dev-b1

Push all changes to all branches

$ git push

Merge a branch to another branch

$ git checkout rc
$ git merge dev-b1
$ git push origin rc

Merge individual commits from another branch

$ git cherry-pick refnumber

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *