Git Command Reference
A modern, copyable cheat sheet for standard Git operations.
Getting & Creating Projects
Initialize a local Git repository
git init
Clone public repository
git clone repo_url
Clone private repository
git clone ssh://git@github.com/[username]/[repository-name].git
Basic Snapshotting
Check status
git status
Add a file to the staging area
git add [file-name]
Add all new and changed files to the staging area
git add -A
Commit changes
git commit -m "[commit message]"
Remove a file (or folder)
git rm -r [file-name.txt]
View the remote repository
git remote -v
Branching & Merging
List of branches
git branch
List all branches (local and remote)
git branch -a
Create a new branch
git branch [branch name]
Delete a branch
git branch -d [branch name]
Delete a branch forcefully
git branch -D [branch name]
Rename a local branch
git branch -m [old] [new]
Switch to a branch
git checkout [branch name]
Switch to the branch last checked out
git checkout -
Create a new branch and switch to it
git checkout -b [branch name]
Discard changes to a file
git checkout -- [file-name.txt]
Merge a branch into the active branch
git merge [branch name]
Stash changes in a dirty working directory
git stash
Apply latest stash to working directory
git stash pop
Remove all stashed entries
git stash clear
Sharing & Updating Projects
Push changes to remote repository
git push
Push a branch to your remote repository
git push origin [branch name]
Push changes to remote and remember branch
git push -u origin [branch name]
Delete a remote branch
git push origin --delete [branch name]
Update local repository to the newest commit
git pull
Pull changes from remote repository
git pull origin [branch name]
Add a remote repository
git remote add origin [url]
Inspection & Comparison
View changes
git log
View changes (briefly)
git log --oneline
Preview changes before merging
git diff [source] [target]
Revert commit changes
git revert [commitid]
Configuration
Set globally Username
git config --global user.name "name"
Set globally Email
git config --global user.email "email"
Get global config
git config --global --list