Git Workbook
Last updated: 08 Apr 2026
Git commands I that are useful to me regularly
Initial Setup
Set username and email
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Basic
Initialise
git init
Add/Stage
git add <file_name> # Stages a single file|
git aad .
Commit
git commit -m “Message” # Commits with a one-line message
| Git Commands | Action Performed |
|---|---|
| git add —all | Stages all files in the repository, including new, modified, and deleted files. |
| git add . | Stages all changes in the current directory. |
| git add -u | Stages only modified and deleted tracked files, ignoring new untracked files. |
Branches
git branch # view local branches
git branch -a # all branches
git branch -r # remote branches
New Branch
git checkout -b <branch_name> # create new branch
Deleting
git branch -d <local branch name>
git push origin -d <remote branch name> # remote branch
Status
git status # full status
git status -s # short status
Intermediate
Push
git push origin <banch_name>
Rename Branch
Local
in the branch
git branch -m <new_name>
From another branch
git branch -m <old_name> <new_name>
Remote
Delete remote branch
git push origin --delete <old_branch>
Push renamed branch
git push origin -u <new_branch>
Logging
git log # Full history
git log --oneline # Summary
git log --reverse
Advanced
Revert to a previous commit
git log # find the specific commit
git revert --no-commit 0d1d7fc3..HEAD
git commit
Rebase
git checkout my-feature-branch
Checkout a new branch from it:
git checkout -b my-feature-branch-backup
Go back to your original branch:
git checkout master
git pull
git checkout my-feature-branch
git rebase origin/master
Git Dubious
git dubious thing solved by git config --global --add safe.directory '*'
Back to log