# A cheat sheet on GIT

Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference

INSTALLATION & GUIS:

With platform specific installers for Git, GitHub also provides the ease of staying up-to-date with the latest releases of the command line tool while providing a graphical user interface for day-to-day interaction, review, and repository synchronization.

GitHub for Windows: Windows GitHub Setup

GitHub for Mac: Mac Github Setup

SETUP:

Configuring user information used across all local repositories:

git config --global user.name “[firstname lastname]”

Sets a name that is identifiable for credit when review version history

git config --global user.email “[valid-email]”

Sets an email address that will be associated with each history marker

git config --global color.ui auto

Sets automatic command line coloring for Git for easy reviewing

INIT:

Configuring user information, initializing and cloning repositories:

Initializes an existing directory as a Git repository

git init

retrieves an entire repository from a hosted location via URL

git clone [URL]

To check the status

git status

To add all the files

git add .

To add the specific file

git add filename

To commit with a message

git commit -m "Your Message"

To push the files into gitrepository

git remote add origin "Repository Link"

Final Push command

git push origin master

Unstaged a file while retaining the changes in the working directory

git reset [file]

diff of what is changed but not staged

git diff

diff of what is staged but not yet committed

git diff --staged

BRANCH & MERGE:

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

git branch

Creates a new branch at the current commit

git branch [branch-name]

shows all commit in the current branch’s history

git log

INSPECT & COMPARE:

git log branchB..branchA

shows the commits on branch A that are not on branch B

git log --follow [file]

shows the commits that changed file, even across renames

git diff branchB...branchA

shows the diff between what is in branch A that is not in branch B

git show [SHA]

TRACKING PATH CHANGES:

Versioning file removes and path changes:

git rm [file]

deletes the file from the project and stage the removal for commit

git mv [existing-path] [new-path]

changes an existing file path and stage the move

git log --stat -M

shows all commit logs with an indication of any paths that moved

SHARE & UPDATE:

Retrieving updates from another repository and updating local repos:

git remote add [alias] [url]

adds a git URL as an alias

git fetch [alias]

fetches down all the branches from that Git remote

git merge [alias]/[branch]

merges a remote branch into your current branch to bring it up to date

git push [alias] [branch]

Transmits local branch commits to the remote repository branch

git pull

fetches and merge any commits from the tracking remote branch

REWRITE HISTORY:

Rewriting branches, updating commits and clearing history:

git rebase [branch]

applies any commits of current branch ahead of specified one

git reset --hard [commit]

clears staging area, rewrite working tree from specified commit

#TEMPORARY COMMITS:

Temporarily store modified, tracked files in order to change branches:

git stash

Saves modified and staged changes

git stash list

lists stack-order of stashed file changes

git stash pop

writes working from the top of stash stack

git stash drop

discard the changes from the top of the stash stack

Hope this cheat sheet helps you. Thank you for using my cheatsheet have a great day. :)