that made me
more aware of what I'm doing
Git-related "best practices" I use for efficiency and exercise
git branch --merged | grep -v "*"|awk '{print "git branch -d " $1}'|bash
git fetch --prune
git pull
git status
git push <remote_probably_origin> <branch> --force-with-lease
git commit ...
# forgot to add something, or wants to replace commit message
git commit ... --amend
git push <remote_probably_origin> <branch> --force-with-lease
git add -p ...
git checkout -p ...
git reset -p ...
git log -p ...
git rebase -i <remote_branch>
# example: git rebase -i origin/develop
git checkout <branch_or_tag_or_commit> -- <path_to_file>
git reflog
git cherry-pick <some-commit-or-a-pointer-to-a-commit>
git log <branch> --graph
git log <branch> --oneline
git log --since="2 weeks ago"
git log --since="1 month ago"
git log --since="2 years ago"
see https://git-scm.com/docs/git-log
git log -- <file-path>
see https://git-scm.com/docs/git-log
Git blame detects the commit with the last change in a line (could be indentation, refactoring, etc.)
Might not be what you want
(to find out where the bug came from)
Then, search for the intended change:
(in Vim) /something ("Enter" and 'n' or 'N' to navigate)
git log -p -m --follow --stat -- path/to/your/file
git rebase <remote-branch>
# ex.: git rebase origin/develop
Not going well?
git rebase --abort
git switch <branch>
# same as git checkout <branch>
git restore
# git reset
# ex: git restore .
# ex.: git restore --staged <file-path>
# ex.: git restore --source <some-commit-hash> <file-path>
More like "tricks"
git remote show <remote_name>
# ex.: git remote show origin
# check HEAD branch field
and what's being tracked
Only the name of the default branch?
git remote show <remote_name> | grep 'HEAD branch' | cut -d' ' -f5