This is list of the git commands I use.
The usual flow of developed is clone or fork a repo, create a branch, change code, create commits at logical stopping points, push those commits, and finally merge the branch (usually done on a website).
Branches let you create a copy all the code from whatever branch you are on. This lets you make changes that can be merged back into the original branch, but doesn't effect the original. They help with conflicting changes by multiple people and code reviews.
git checkout main
git pull
git checkout -b <branch name>
git push origin HEAD
Note: If your commit is amended or you deleted a commit you can force the changes
git push origin HEAD --force
git checkout main
git pull
git checkout -
git rebase main
git push origin HEAD
git branch -d <branchName>
git branch --merged | egrep -v "(^\*|master|main)" | xargs git branch -d
Commits let you save current changes in a name on your local computer. Commits can later be pushed to a repo.
git commit -am "<commit message>"
git commit --amend
git commit --amend --no-edit
git reset --soft HEAD~
# If you are on main
git add .
git commit -m tmp
git pull --rebase
git reset --soft HEAD~
# If you are on another branch
git commit -am tmp
git fetch
git rebase origin/main
git reset --soft HEAD~
git pull origin `git branch --show-current`
git checkout -
git remote add upstream <repo location>
git fetch upstream
git rebase upstream/main
git push origin HEAD
Find a commit hash. It is on the left in this command:
git log --abbrev-commit --pretty=oneline
Cherry pick the commit
git cherry-pick <commit hash>
git update-index --skip-worktree <file path>
# Undo
git update-index --no-skip-worktree <file path>
This might work better in some situations
git update-index --assume-unchanged <file path>
# Undo
git update-index --no-assume-unchanged <file path>
The normal way to look through history
git log
To make that eaiser to follow create an alias then use it. Copied from here.
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold yellow)<%an>%Creset' --abbrev-commit"
git logline