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.

git commit -m "π‡πžπ₯π₯𝐨 𝐭𝐑𝐞𝐫𝐞, 𝐟𝐞π₯π₯𝐨𝐰 <πšπšŽπšŸπšŽπš•πš˜πš™πšŽπš›πšœ />!" made with ❀️

GIT BASICS
  1. git init [directory]
    Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.
  2. git clone [repo]
    Clone repo located at onto local machine. Original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.
  3. git config user.name [name]
    Define author name to be used for all commits in current repo. Devs commonly use --global flag to set config options for current user.
  4. git add [directory]
    Stage all changes in directory for the next commit. Replace directory with a file to change a specific file.
  5. git commit -m "message"
    Commit the staged snapshot, but instead of launching a text editor, use message as the commit message.
  6. git status
    List which files are staged, unstaged, and untracked.
  7. git log
    Display the entire commit history using the default format. For customization see additional options.
  8. git diff
    Show unstaged changes between your index and working directory.
Configuring user information, initializing and cloning repositories
REWRITING GIT HISTORY
  1. git commit --amend
    Replace the last commit with the staged changes and last commit combined. Use with nothing staged to edit the last commit's message.
  2. git rebase [base]
    Rebase the current branch onto base. base can be a commit ID, branch name, a tag, or a relative reference to HEAD.
  3. git reflog
    Show a log of changes to the local repository's HEAD. Add --relative-date flag to show date info or --all to show all refs.
  4. git reset --hard [commit]
    clear staging area, rewrite working tree from specified commit
Rewriting branches, updating commits and clearing history
GIT BRANCHES
  1. git branch
    List all of the branches in your repo. Add a branch rgument to create a new branch with the name branch.
  2. git checkout -b [branch]
    Create and check out a new branch named branch. Drop the -b flag to checkout an existing branch.
  3. git branch [branch-name]
    create a new branch at the current commit
  4. git branch [-a]
    List all local branches in repository. With -a: show all branches (with remote).
Isolating work in branches, changing context, and integrating changes
REMOTE REPOSITORIES
  1. git remote add [name] [url]
    Create a new connection to a remote repo. After adding a remote, you can use name as a shortcut for url in other commands.
  2. git fetch [remote] [branch]
    Fetches a specific branch, from the repo. Leave off branch to fetch all remote refs.
Repository that's hosted on the Internet or another network.
GIT MERGE
  1. git merge [branch-name]
    merge the specified branch's history into the current one
  2. git merge [alias]/[branch-name]
    merge a remote branch into your current branch to bring it up to date
Retrieving updates from another repository
UNDOING CHANGES
  1. git revert [commit]
    Create new commit that undoes all of the changes made in commit, then apply it to the current branch.
  2. git reset [file]
    Remove file from the staging area, but leave the working directory unchanged. This unstages a file without overwriting any changes.
  3. git clean -n
    Shows which files would be removed from working directory. Use the -f flag in place of the -n flag to execute the clean.
Working with snapshots and the Git staging area

Additional Options

GIT DIFF
  1. git diff HEAD
    Show difference between working directory and last commit.
  2. git diff --cached
    Show difference between staged changes and last commit
  3. git diff --staged
    diff of what is staged but not yet committed
  4. git diff branchB ... branchA
    Show the diff of what is in branchA that is not in branchB.
Examining diffs
GIT SHOW
  • git show [SHA]
    show any object in Git in human-readable format
Examining object information
GIT RESET
  1. git reset
    Reset staging area to match most recent commit, but leave the working directory unchanged.
  2. git reset --hard
    Reset staging area and working directory to match most recent commit and overwrites all changes in the working directory.
  3. git reset [commit]
    Move the current branch tip backward to commit, reset the staging area to match, but leave the working directory alone.
  4. git reset --hard [commit]
    Same as previous, but resets both the staging area & working directory to match. Deletes uncommitted changes, and all commits after commit.
TEMPORARY COMMITS
  1. git stash
    Save modified and staged changes
  2. git stash list
    list stack-order of stashed file changes
  3. git stash pop
    write working from top of stash stack
  4. git stash drop
    discard the changes from top of stash stack
Temporarily store modified, tracked files in order to change branches
GIT REBASE
  • git rebase -i [base]
    Interactively rebase current branch onto nase. Launches editor to enter commands for how each commit will be transferred to the new base.
TRACKING PATH CHANGES
  1. git rm [file]
    Delete the file from project and stage the removal for commit.
  2. git mv [existing-path] [new-path]
    Change an existing file path and stage the move.
  3. git log --stat -M
    Show all commit logs with indication of any paths that moved.
Versioning file removes and path changes.
IGNORING PATTERNS
  1. logs/
    *.notes
    pattern*/
    Save a file with desired patterns as .gitignore with either direct string matches or wildcard globs.
  2. git config --global core.excludesfile [file]
    System wide ignore pattern for all local repositories.
  3. Subheading
    Content for list item
Preventing unintentional staging or commiting of files.

THE ZOO OF WORKING AREAS
working-area
  • Commit
  • an object
  • Branch
  • a reference to a commit; can have a tracked upstream
  • Tag
  • a reference (standard) or an object (annotated)
  • Head
  • a place of working directory is now

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 Desktop - Focus on what matters instead of fighting with Git. Whether you're new to Git or a seasoned user, GitHub Desktop simplifies your development workflow. for more, Click here

If you want to use GitHub on your Mac, you can download the GitHub from Click here.

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.

For Linux and Solaris platforms, the latest release is available on the official Git web site.