Git Commands Reference
Complete Git commands reference with copy functionality. Comprehensive list of Git commands with descriptions and usage examples for developers and version control workflow.
Basic Commands
git init
Initialize a new Git repository
git clone <repository-url>
Clone a repository from remote source
git status
Show the working tree status
git help
Display help information about Git
Repository Management
git remote -v
Show remote repositories
git remote add origin <url>
Add a remote repository
git remote remove <name>
Remove a remote repository
git remote rename <old> <new>
Rename a remote repository
Branch Operations
git branch
List all local branches
git branch -a
List all branches (local and remote)
git branch <branch-name>
Create a new branch
git checkout <branch-name>
Switch to a branch
git checkout -b <branch-name>
Create and switch to a new branch
git switch <branch-name>
Switch to a branch (newer syntax)
git switch -c <branch-name>
Create and switch to a new branch (newer syntax)
git branch -d <branch-name>
Delete a merged branch
git branch -D <branch-name>
Force delete a branch
git merge <branch-name>
Merge a branch into the current branch
Staging & Committing
git add <file>
Add a file to the staging area
git add .
Add all files to the staging area
git add -A
Add all files including deleted ones
git add -p
Interactively add changes
git commit -m "message"
Commit changes with a message
git commit -a -m "message"
Add and commit all tracked files
git commit --amend
Amend the last commit
git reset <file>
Unstage a file
Remote Operations
git fetch
Download objects and refs from remote
git pull
Fetch and merge changes from remote
git pull origin <branch>
Pull specific branch from origin
git push
Push changes to remote repository
git push origin <branch>
Push branch to origin remote
git push -u origin <branch>
Push and set upstream branch
git push --force
Force push (use with caution)
Viewing History
git log
Show commit history
git log --oneline
Show commit history in one line
git log --graph
Show commit history with graph
git show <commit>
Show changes in a commit
git diff
Show changes between working tree and index
git diff --staged
Show changes between index and HEAD
git blame <file>
Show who changed each line
Undoing Changes
git checkout -- <file>
Discard changes in working directory
git restore <file>
Restore working tree files (newer syntax)
git restore --staged <file>
Unstage file (newer syntax)
git reset --soft HEAD~1
Undo last commit, keep changes staged
git reset --mixed HEAD~1
Undo last commit, unstage changes
git reset --hard HEAD~1
Undo last commit, discard all changes
git revert <commit>
Create new commit that undoes changes
Tagging
git tag
List all tags
git tag <tag-name>
Create a lightweight tag
git tag -a <tag> -m "message"
Create an annotated tag
git tag -d <tag-name>
Delete a local tag
git push origin <tag>
Push a tag to remote
git push --tags
Push all tags to remote
Stashing
git stash
Stash current changes
git stash save "message"
Stash changes with a message
git stash list
List all stashes
git stash pop
Apply and remove the latest stash
git stash apply
Apply the latest stash without removing it
git stash drop
Delete the latest stash
git stash clear
Delete all stashes
Configuration
git config --list
List all configuration
git config user.name "name"
Set user name
git config user.email "email"
Set user email
git config --global user.name
Set global configuration
git config core.editor "editor"
Set default editor
Advanced Commands
git rebase <branch>
Rebase current branch onto another
git rebase -i HEAD~n
Interactive rebase last n commits
git cherry-pick <commit>
Apply a commit from another branch
git bisect start
Start binary search for bug
git reflog
Show reference logs
git clean -fd
Remove untracked files and directories
git submodule add <url>
Add a submodule
git worktree add <path>
Create a new worktree