Skip to content

Git Cheat Sheet

George Robertson edited this page Apr 16, 2021 · 10 revisions

The below git commands have taken from an online cheat sheet. The commands can be entered into GitBash/Command prompt.

GitClone

$ git clone [URL] 

Retrieve an entire repository from GitHub via URL

GitBasics

$ git branch 

List your branches. a * will appear next to the currently active branch.

$ git status

Check current working branch for untracked files or can be used to check current local branch against remote branch.

$ git checkout {branch_name}

Switch to another branch and check it out into your working directory.

$ git checkout -b{branch_name}

Create a new local branch

$ git checkout -b{branch_name} --track {remote_branch_name}

Create a new local branch tracking a remote branch.

$ git pull

Fetch and merge any commits from the tracking remote branch.

$ git pull origin master

Pull latest commits from master branch. It is highly advised that you pull from the master branch regularly to limit merge conflicts.

$ git add {path+filename}
$ git add .
$ git add --patch

Add a file/s as it looks now to your next commit (stage).

$ Git commit -m “[descriptive message]"

Commit your staged content as a new commit snapshot.

$ git push [alias][branch]

Transmit local branch commits to remote repository branch.



This is not an exhaustive document of the most common GitBash commands. If there are any you use frequently that have been missed additions are welcomed.