Skip to content

Giton-App/git-essentials-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Essential Git Cheat Sheet

A summary of commonly used Git command-line instructions for quick reference.


Setup & Init

Configuring user information, initializing, and cloning repositories.

Set your username

Set a name that is identifiable for credit when reviewing version history.

git config --global user.name "[firstname lastname]"

Set your email Set an email address that will be associated with each history marker.

git config --global user.email "[valid-email]"

Enable helpful colorization Set automatic command line coloring for Git for easy reviewing.

git config --global color.ui auto

Initialize a new repository Initialize an existing directory as a Git repository.

git init

Clone a repository Retrieve an entire repository from a hosted location via URL.

git clone [url]

Stage & Snapshot

Working with snapshots and the Git staging area.

Check status Show modified files in the working directory, staged for your next commit.

git status

Stage a file Add a file as it looks now to your next commit (stage). (Tip: use git add . to stage all changes).

git add [file]

Unstage a file Unstage a file while retaining the changes in your working directory.

git reset [file]

View unstaged changes Diff of what is changed but not staged.

git diff

View staged changes Diff of what is staged but not yet committed.

git diff --staged

Commit changes Commit your staged content as a new commit snapshot.

git commit -m "[descriptive message]"

Branch & Merge

Isolating work in branches, changing context, and integrating changes.

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

git branch

Create a branch Create a new branch at the current commit.

git branch [branch-name]

Switch branches Switch to another branch and check it out into your working directory. (Tip: git switch [branch-name] is a modern alternative).

git checkout [branch-name]

Merge a branch Merge the specified branch's history into the current one.

git merge [branch]

Share & Update

Retrieving updates from another repository and updating local repos.

Add a remote Add a Git URL as an alias.

git remote add [alias] [url]

Fetch from remote Fetch down all the branches from that Git remote.

git fetch [alias]

Merge a remote branch Merge a remote branch into your current branch to bring it up to date.

git merge [alias]/[branch]

Push to remote Transmit local branch commits to the remote repository branch.

git push [alias] [branch]

Pull from remote Fetch and merge any commits from the tracking remote branch.

git pull

Inspect & Compare

Examining logs, diffs, and object information.

View commit history Show the commit history for the currently active branch.

git log

Compare branches (commits) Show the commits on branchA that are not on branchB.

git log branchB..branchA

View file commit history Show the commits that changed a file, even across renames.

git log --follow [file]

Compare branches (diff) Show the diff of what is in branchA that is not in branchB.

git diff branchB...branchA

Show object details Show any object in Git in a human-readable format.

git show [SHA]

Tracking Path Changes

Versioning file removes and path changes.

Delete a file Delete the file from the project and stage the removal for commit.

git rm [file]

Move or rename a file Change an existing file path and stage the move.

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

Show moved files in logs Show all commit logs with indication of any paths that moved.

git log --stat -M

Temporary Commits

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

Stash changes Save modified and staged changes.

git stash

List stashes List stack-order of stashed file changes.

git stash list

Pop a stash Write working from the top of the stash stack.

git stash pop

Drop a stash Discard the changes from the top of the stash stack.

git stash drop

Rewrite History

Rewriting branches, updating commits, and clearing history.

Rebase a branch Apply any commits of the current branch ahead of the specified one.

git rebase [branch]

Hard reset Clear staging area, rewrite working tree from specified commit. (Warning: This discards local changes!)

git reset --hard [commit]

About

A clean, Markdown-formatted reference guide of essential Git commands. Includes common workflows, branching, syncing, and history management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors