Branches in GitHub Cheat Sheet
Creating branches
git branch <name>
Creating branch in a revision
git branch <branch-name> <commit Id> --> This will create a new branch in the commit indicated, where the head of that branch will be that commit indicated and showing the past commits too.
Switching Branches
git checkout <mybranch> or git switch <branch-name>
See all my branches
git branch
Rename Branches
git branch -m <new-name> {--- update current branch
git branch -m <old-name> <my-new-name> {--- change a name of a branch given a name.
Tracking Branches
git checkout --track origin/<branch-name>
git branch -v {-- show me information about every branch [ahead, behind], ahead means I have a local commit hat I haven't push yet, behind means I am behind remote n commits I haven't pull.
Delete Branches
git push origin --delete <branch>/<sub-branch>
git branch -d <branch-name>
Merging Branches
(1) Check out the branch that should receive the changes
git switch main
(2) Execute the merge command with the name of the branch that contains the desired changes
git merge my-branch
Rebasing Branches
This is an alternative to integrating changes from another branch into your current local Head branch.
git rebase my-branch
Comparing Branches
git log main..my-branch
This show what commits are in <my-branch> but not in main branch
git log origin/main..main
This compares the remote main branch with the main local branch.