$ git config --global init.defaultBranch main
$ git config --global merge.conflictstyle diff3
Ignore a file locally:
.git/info/exclude
https://stackoverflow.com/questions/1753070/how-do-i-configure-git-to-ignore-some-files-locallySign a past commit
git rebase --interactive
git commit --amend --no-edit -S
-w
- ignore whitespace in commands that show diffs--color-words
- show words removed and added within linesgit config --global user.name "Whatev"
git config --global user.email "email@example.com"
git config user.name "Whatev"
git config user.email "email@example.com"
git init
git clone [REPO URL]
git clone --depth 1 [REPO URL]
git log — show commit history
-p — include diffs
-p --full-history --first-parent - show diffs for merges too
git status — show state of working copy
git show [COMMIT HASH] - diffs
git diff [COMMIT HASH 1] [COMMIT HASH 2]
git diff — shows diffs in working copy
git checkout -- [FILE NAME] — undo local changes to file
git reset --hard HEAD — undo all local changes
git stash — stashes current changes
git stash save "stash name" — stashes under a name
git stash list — shows stashes
git stash pop — apply latest stash
git stash apply stash@{#}
git stash drop stash@{#}
git add filenames — add files to the staging area
git reset filenames — remove files from the staging area
git rm filenames — record the removal of a file in the staging area
git add -A — add all new files
git add -p — pick add
git diff --cached — show diffs in staging area
git commit -m "my commit message"
git commit --amend -m "new message" — change the commit message OR the files
git commit --amend --no-edit —change the commit files, no message prompt
git commit --allow-empty -m "new message" — commit with only a message, no file changes
git branch -v — list branches
git branch -va — list branches including remote
git branch [NEW BRANCH NAME] — creates a branch, doesn't switch to it
git branch -d [BRANCH NAME] — deletes
git branch -dr [REMOTE BRANCH NAME] — deletes a remote branch
git checkout [BRANCH NAME]
git checkout -b [BRANCH NAME] — create and check out a new branch
git checkout --track [REMOTE BRANCH NAME]
git merge [BRANCH NAME] — merges named branch into HEAD
git merge --no-ff [BRANCH NAME] — merges named branch always including a merge commit
git remote add [REMOTENAME] [REMOTEURL]
git remote -v —list remotes
git remote set-url [REMOTEURL] [URL]
git fetch [REMOTENAME] — download info on the state of that remote's branches
git pull — pull remote tracked branch to HEAD
git push — push HEAD to remote tracked branch
git push [REMOTENAME] [BRANCHNAME]
git push -u [REMOTENAME] [BRANCHNAME] — sets up tracking
git push --force [REMOTENAME] [BRANCHNAME]
git revert [COMMIT HASH] — reverse the effects
git reset --hard [COMMIT HASH] — resets HEAD to there
git reset --soft [COMMIT HASH] — resets HEAD and moves changes back to staged
git rebase --interactive [COMMIT HASH] — lets you re-step through history to change files or comments
git rebase --continue — move past current step
git rebase --abort — cancel interactive rebase
git checkout [COMMIT HASH] file — overwrite a file with an older version of it
git cherry-pick [COMMIT HASH]
git tag -d [TAG NAME] -- delete a tag
Use oh-my-zsh with the git-extras plugin.
git
at the front so that autocomplete will work - see https://github.com/CodingItWrong/dotfiles/blob/master/.gitconfig - example: git b
for git branch
B. For shortcuts that don’t need autocomplete, you can set them up in .bash_profile and then you won’t need to type git
in front - see https://github.com/CodingItWrong/dotfiles/blob/master/.bash_profile - example: gri
for git rebase --interactive