Git Handbook
Trying to save time I spend revisiting the same git stackoverflow answers.
Git?
It is git.
Branching 101
Read more from here.
Working locally
# list all the local branches
git branch
# list all the remote branches
git branch -a
# list all branches verbose
git branch -v -a
# just make new branch
git branch <branch>
# switch to branch
git switch <branch>
# delete branch
git branch -d <branch>
# force delete branch
git branch -D <branch>
# rename current branch
git branch -m <branch>
# make a new branch, switch current working directory
git checkout -b <branch>
# if branch already exists
git checkout <branch>
Working with Remote
# list remote
git remote
# list remote with links
git remote -v
# add new remote
git remote add <name> <url>
# add remove remote
git remote rm <name>
# rename remote
git remote rename <old_name> <new_name>
Reset local branch to match remote branch
git fetch origin
git branch -v -a
git reset --hard <remote>/<branch>
How do I check out a remote Git branch?
# create a new branch of name test
git fetch origin
git branch -v -a
git switch -c test origin/test
Squash last n commits into single commit
# squash last 2 commits into single commit
git reset --soft HEAD~2
git commit
Edit a previous commithere.
# suppose you want to edit commit `bbc643cd`
# ~ at the last is important
git rebase --interactive bbc643cd~
# change `pick` to `edit` of bbc643cd
# ammend your commit
git commit --all --amend
git rebase --continue
Change the Windows CRLF to Unix LF
git config --global core.autocrlf false
git rm --cached -r .
git reset --hard