Git Commands Quick Ref
git status
git add [files]
git diff
git difftool
git diff --staged
- diff of what is changed but not staged
git commit -m "[descriptive message]"
git commit -am "[descriptive message]"
- commit and add all modified files to commit
branches
git branch
- list branches (local)
- Switches:
-r
- remote,-a
- all
git branch [branch-name]
- creates a new branch at current commit
git checkout
- switch to another branch and check it out
git merge [branch]
- merge the specified branch into the current one.
Logs
git log
- shows a log of all commits on current branch
git log --follow [file]
- show commits that chanced the file (even across renames)
share & remotes
git remote add [alias] [url]
- add a git URL as an alias
git fetch [alias]
- fetch all branches from alias remote
git push
- pushes to remote
git pull
- fetch and merge from remote
Rewrite History
git rebase [branch]
- apply any commit of current branch ahead of specified one
Stash / temp storage
git stash
— stashes current changes
git stash save "some message"
— stashes current changes with a short message
git stash pop
— restores last stash
git stash show
— shows changes in most recent stash
Worktrees
Allows easy way to work on multiple branches at the same time.
git worktree add <main>
— adds the worktree & branch 'main'
git [worktree](worktree) add <location-local> <branch-name>
— adds the worktree main
git worktree list
— lists all worktree directories and currently checkedout branch
git worktree remove
— removes a worktree from the repo
git worktree prune
— removes worktrees that are no longer valid