The git command
the stupid content tracker 49 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.
Subcommands in the examples
git add- Add file contents to the index
git commit- Record changes to the repository
git log- Show commit logs
git branch- List, create, or delete branches
git diff- Show changes between commits, commit and working tree, etc
git push- Update remote refs along with associated objects
git status- Show the working tree status
git switch- Switch branches
git clone- Clone a repository into a new directory
git config- Get and set repository or global options
git pull- Fetch from and integrate with another repository or a local branch
git remote- Manage set of tracked repositories
git blamegit checkout- Switch branches or restore working tree files
Examples
git --version
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git init
git status
git add file.txtStage one file
git add file1.txt file2.txt
git add .Stage everything in current directory
git add -AStage everything in the whole repo
git commit -m "Add initial project files"
git commit -am "Fix typo in README"
git restore --staged file.txtUnstage, keep changes
git commit -m "stuff"
git commit -m "Fix login redirect bug for expired sessions"
git log
git log --onelineCompact, one line per commit
git log --oneline --graphASCII graph of branches
git log -n 5Last 5 commits
git log --author="Ana"Filter by author
git diffUnstaged changes vs last commit
git diff --stagedStaged changes vs last commit
git diff HEAD~1 HEADCompare two commits
git diff file.txtChanges in one file
git show a1b2c3d
git blame file.txt
git branch feature-loginCreate
git switch feature-loginSwitch (modern)
git checkout feature-loginSwitch (classic)
git switch -c feature-loginCreate + switch in one step
git branchLocal branches
git branch -aAll, including remote
git switch main
git merge feature-login
git commit
git branch -d feature-loginSafe delete (merged only)
git branch -D feature-loginForce delete
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git my-folder
git remote add origin https://github.com/user/repo.git
git remote -vList configured remotes
git push origin main
git push -u origin main-u remembers this pairing for future plain `git push`
git pull origin mainfetch + merge in one step
git fetch originJust download, don't merge yet
git pullGet latest changes
git commit -m "Add feature X"
git push
git commit -m "Ship feature: user dashboard"
git log --oneline -n 3