Git Commands
Essential Git commands for daily use
| Command | Description | |
|---|---|---|
git init | Initialize a new Git repository | |
git clone <url> | Clone a remote repository | |
git status | Show working tree status | |
git add . | Stage all changes | |
git add <file> | Stage a specific file | |
git commit -m "msg" | Commit staged changes with message | |
git push | Push commits to remote | |
git push -u origin <branch> | Push and set upstream for a new branch | |
git pull | Fetch and merge from remote | |
git fetch | Download objects from remote without merging | |
git branch | List local branches | |
git branch <name> | Create a new branch | |
git checkout <branch> | Switch to a branch | |
git checkout -b <branch> | Create and switch to a new branch | |
git merge <branch> | Merge a branch into current branch | |
git rebase <branch> | Rebase current branch onto another | |
git stash | Stash uncommitted changes | |
git stash pop | Apply and remove last stash | |
git log --oneline | Show compact commit history | |
git log --graph | Show commit history as a graph | |
git diff | Show unstaged changes | |
git diff --staged | Show staged changes | |
git reset HEAD <file> | Unstage a file | |
git reset --soft HEAD~1 | Undo last commit, keep changes staged | |
git reset --hard HEAD~1 | Undo last commit and discard changes | |
git revert <commit> | Create a new commit that undoes a previous commit | |
git cherry-pick <commit> | Apply a specific commit to current branch | |
git tag <name> | Create a lightweight tag | |
git remote -v | List remote repositories | |
git config --global user.name "Name" | Set global Git username | |
git clean -fd | Remove untracked files and directories | |
git bisect start | Start binary search for a bad commit | |
git blame <file> | Show who changed each line | |
git show <commit> | Show details of a specific commit | |
git reflog | Show history of HEAD movements |