Brief git Cheat Sheet

Brief git Cheat Sheet

quick start with Git



👣 #git #scss #sass

Install Git

Git distributions for all platforms are available on the official Git SCM (Software Configuration Management) web site -

Configure tooling

Configure user information for all local repositories.

git config --global "[name]"
# sets the name you want attached to your commit transactions
git config --global "[email address]"
# sets the email you want attached to your commit transactions
git config --global color.ui auto
# enables helpful colourization of command line output

Create repositories

When starting out with a new repository, you only need to do it once; either locally, then push to Git host sites, or by cloning an existing repository.

git init
# turn an existing directory into a git repository
git clone [url]
# clone (download) a repository that already exists on Git host sites,
# including all of the files, branches, and commits


Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Use git status to see which branch that is.

git branch [branch-name]
# creates a new branch
git checkout [branch-name]
# switches to the specified branch and updates the working directory
git merge [branch]
# combines the specified branch's history into the current branch
# this is usually done in pull requests, but is an important Git operation
git branch -d [branch-name]
# deletes the specified branch

The .gitignore file

Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore. You can find help templates for .gitignore files at for different projects.

Synchronize changes

Synchronize your local repository with the remote repository on Git host sites.

git fetch
# downloads all history from the remote tracking branches
git merge
# combines remote tracking branch into current local branch
git push
# uploads all local branch commits to Git host sites
git pull
# updates your current local working branch
# with all new commits from the corresponding remote branch
# 'git pull' is a combination of 'git fetch' & 'git merge'

Make changes

Browse and inspect the evolution of project files.

git log
# lists version history of the current branch
git log --follow [file]
# lists version history for a file, including renames
git diff [first-branch]...[second-branch]
# shows content differences between two branches
git show [commit]
# outputs metadata and content changes of the specified commit
git add [file]
# snapshots the file in preparation for versioning
git commit -m "[descriptive message]"
# records file snapshots permanently in version history

Redo commits

Erase mistakes and craft replacement history.

git reset [commit]
# undoes all commits after [commit], preserving changes locally
git reset --hard [commit]
# discards all hostory and changes back to the specified commit

CAUTION! Changing history can have nasty side effects. If you need to change commits that exist on remote Git host sites, proceed with caution.

Git Flow


  • git: an open source, distributed version-control system
  • commit: a Git object, a snapshot of your entire repository compressed into a SHA
  • branch: a lightweight movable pointer to a commit
  • clone: a local version of a repository, including all commits and branches
  • remote: a common repository on Git host sites that all team member use to exchange their changes
  • fork: a copy of a repository on Git host sites that owned by a different user
  • pull request: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more
  • HEAD: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using git checkout
Ads by Google


Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.


Using Liquid in Jekyll - Live with Demos

Web Notes


Using Liquid in Jekyll - Live with Demos

Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.

Setup an IKEv2 server with strongSwan



Setup an IKEv2 server with strongSwan

IKEv2, or Internet Key Exchange v2, is a protocol that allows for direct IPSec tunnelling between networks. It is developed by Microsoft and Cisco (primarily) for mobile users, and introduced as an updated version of IKEv1 in 2005. The IKEv2 MOBIKE (Mobility and Multihoming) protocol allows the client to main secure connection despite network switches, such as when leaving a WiFi area for a mobile data area. IKEv2 works on most platforms, and natively supported on some platforms (OS X 10.11+, iOS 9.1+, and Windows 10) with no additional applications necessary.

First taste of Heroku, h5ai for a file indexer



First taste of Heroku, h5ai for a file indexer

I've known Heroku for a long time, but never have a try to build with it. This time, I found a beautiful file indexer, h5ai, that requires PHP 5.5+, and Heroku is a perfect platform to build and host it.