Git Commands ๐
Common Git Commands¶
This cheat-sheet lists common Git commands and also includes recommended branching strategies and useful aliases.
| Command | Description |
|---|---|
git init | Initialize a local Git repository |
git clone <url> | Clone a repository |
git status | Show working tree status |
git add <file> | Stage changes |
git commit -m "msg" | Commit staged changes |
git branch | List branches |
git checkout -b <branch> | Create and switch to a branch |
git checkout <branch> | Switch to a branch |
git merge <branch> | Merge a branch into the current branch |
git rebase <branch> | Rebase current branch onto another |
git stash | Save local changes temporarily |
git pull | Fetch + merge remote changes |
git push | Push changes to remote |
git log --oneline --graph --decorate | Compact history view |
Branching strategies¶
- GitFlow: Feature branches, develop branch, release branches, and
mainfor production. Good for larger teams with releases. - Trunk-Based Development: Small short-lived branches or direct commits to
mainwith feature toggles; encourages frequent integration.
Choose a strategy that matches your release cadence and team size.
Useful aliases & tips¶
Add these to your ~/.gitconfig to speed up workflows:
[alias]
st = status
co = checkout
br = branch
ci = commit
lg = log --oneline --graph --decorate --all
Always pull remote changes before starting significant work, and prefer short-lived branches with CI validations on PRs.
If you want, I can add a small git-workflow.md that documents a recommended workflow (PR template, branch protections, and CI checks).