| Command | What it does |
|---|---|
git init | Create a new git repository in the current directory. |
git clone <url> | Copy a remote repository to the local machine. |
git status | Show the state of the working tree and staging area. |
git add <file> | Stage a file for the next commit. |
git add -p | Interactively stage individual hunks of changes. |
git commit -m "msg" | Record staged changes as a new commit with a message. |
git log --oneline | Show a compact list of recent commits. |
git diff | Show unstaged changes relative to the last commit. |
git diff --staged | Show staged changes relative to the last commit. |
git show <hash> | Show the diff and metadata of a specific commit. |
git restore <file> | Discard unstaged changes to a file. |
git reset HEAD <file> | Unstage a file without discarding changes. |
# create and switch to a new branch
git checkout -b feature/regex-flags
# ... make commits on the feature branch ...
# switch back to main and merge
git checkout main
git merge feature/regex-flags
# delete the branch after merging
git branch -d feature/regex-flags
| Command | What it does |
|---|---|
git remote add origin <url> | Register a remote named "origin". |
git push -u origin main | Push local main to origin and set tracking. |
git push | Push current branch commits to the tracked remote branch. |
git fetch | Download remote changes without merging. |
git pull | Fetch and merge (or rebase) remote changes into current branch. |
git pull --rebase | Fetch remote changes and rebase local commits on top. |
| Resource | Description |
|---|---|
| Pro Git (free online) | Complete git reference from first commits through advanced internals. |
| GitHub Flow | GitHub's guide to the GitHub Flow branching model. |
| Git Flow | The original Git Flow article by Vincent Driessen. |
| SW Deploy Bites: Git | Git configuration management from the Deploy Bites sequence in this track. |