GIT cheat sheets

Here I list the common GIT codes

Installing Git
Download GIT for Windows OS.


// for Windows

Download GIT for Mac.


// for Mac

Download GIT for all platforms


// for all platforms

Configure Tooling

To Sets the name you want attached to your commit transactions

// set name
$ git config --global "[name]"

Sets the email you want attached to your commit transactions

// set email
$ git config --global "[email address]"

Enables helpful colorization of command line output

// enable color
$ git config --global color.ui auto

Create Repositories

Creates a new local repository with the specified name

// Create local repositories
$ git init [project-name]

Downloads a project and its entire version history

// Download project
$ git clone [url]

See Initiating the Git

Make Changes

Lists all new or modified files to be committed

// List all un committed files
$ git status

Shows file differences not yet staged

// Differences which are not yet staged
$ git diff

Snapshots the file in preparation for versioning

// add a file
$ git add [file]

// add all files
$ git add .

// add multiple files at once with file name
$ git add [file 1] [file 2] [file 3] [file 4] [...] [file n]

Shows file differences between staging and the last file version

// show difference of staging and last version
$ git diff --staged

Unstages the file, but preserve its contents

// unstage
$ git reset [file]

Records file snapshots permanently in version history

// commit changes
$ git commit -m "[descriptive message]"

If the file is under git track we can combine both comments in one line like

// commit file under track
$ git commit -am "[descriptive message]"
// OR
$ git commit -a -m "[descriptive message]"
// here -a to add
// -m to commit message

Group Changes

Lists all local branches in the current repository

// list branches
$ git branch

Creates a new branch

// new branch
$ git branch [branch-name]

Switches to the specified branch and updates the working directory

// checkout to a branch
$ git checkout [branch-name]

Combines the specified branch’s history into the current branch

// merge a branch
$ git merge [branch]

Deletes the specified branch

// delete branch
$ git branch -d [branch-name]

Hard Deletes the specified branch – Force Delete the branch

// Hard delete
$ git branch -D [branch-name]

Delete Remote branch

// delete remote branch
$ git push origin --delete [branch-name]

Refactor Filenames

Deletes the file from the working directory and stages the deletion

// delete file
$ git rm [file]

Removes the file from version control but preserves the file locally

// delete file but preserves in locally
$ git rm --cached [file]

Changes the file name and prepares it for commit

// change file name
$  git mv [file-original] [file-renamed]

Save Fragments

Temporarily stores all modified tracked files

//  stash the changes
$  git stash

Restores the most recently stashed files

// restore the recent stash
$  git stash pop

Lists all stashed change sets

// list the stash
$  git stash list

Discards the most recently stashed change set

// delete the recent stash
$  git stash drop

Review History

Lists version history for the current branch

// list the history/log
$  git log

Lists version history for a file, including renames

// list the history/log with file name
$  git log --follow [file]

Shows content differences between two branches

// display difference of two branch
$  git diff [first-branch]...[second-branch]

Shows content differences between two commit

// display difference of two commit
$  git diff [first-commit]...[second-commit]

Outputs metadata and content changes of the specified commit

// display content changes in a commit
$  git show [commit]

Synchronize Changes

Downloads all history from the repository bookmark

// download bookmark
$   git fetch [bookmark]

Combines bookmark’s branch into current local branch

// merge bookmark into branch
$  git merge [bookmark]/[branch]

Uploads all local branch commits to GitHub

// upload 
$  git push [alias] [branch]

$ git push origin master

Downloads bookmark history and incorporates changes

// download
$  git pull [alias] [branch]

$ git pull origin master

Redo Commits

Undoes all commits after [commit] , preserving changes locally

// undo commits
$   git reset [commit]

Discards all history and changes back to the specified commit

// Discard hard
$   git reset --hard [commit]

Discards all history and changes back to the specified branch

// Discard  to a branch
$   git reset --hard [branch]

Discard all history and change back to the remote branch

// Discard  to a remote branch
$   git reset --hard origin/[branch]

Track and Untrack the files

This will tell git you want to start ignoring the changes to the file

$ git update-index --assume-unchanged path/to/file

When you want to start keeping track again

$ git update-index --no-assume-unchanged path/to/file

Git UI

Display User friendly window

//display UI window
$ gitk