Git Commands

General

CommandDescription
git initCreate a new Git repository
git add <file>Add file to staging area
git rm <file>Remove file from repository
git mv <from> <to>Move or rename file
git commitCommit staged changes
git statusShow working tree status
git logShow commit history
git log --decorateShow commit history with tags
git log --grep="<search>"Search through commit messages
git remote add origin <url>Add remote repository

Branches

CommandDescription
git branchList all branches
git branch <branch>Create a new branch
git checkout -b <branch>Create and checkout branch
git checkout <branch>Switch to branch
git branch -m <from> <to>Rename branch
git branch -d <branch>Delete local branch
git push origin :<branch>Delete remote branch
git diff <branch>Show changes between branches
git merge <branch>Merge branch into current
mate <file> git add <file> git commitResolving merge conflicts
git checkout -f masterDiscard branch changes

Tags

CommandDescription
git tagList all tags
git tag -a <tag>Create a new tag
git tag -a <tag> <commit>Create tag for specific commit
git show <tag>Show tag details
git tag -d <tag>Delete local tag
git push origin :refs/tags/<tag>Delete remote tag

Push & Pull

CommandDescription
git push origin masterPush to master branch
git push origin master --tagsPush with tags
git fetch originFetch from remote repository
git merge origin/masterMerge remote branch into current
git pullFetch and merge into current branch

Clone & Submodules

CommandDescription
git clone <url>Clone repository
git clone --recursive <url>Clone with submodules
git submodule add <url>Add submodule to repository
git submodule updateUpdate submodule