1.4. Branching#
Changes to code are saved with pointers to the commit snapshots
Allowing you to revert to a prior version
The first branch is typically
main
git branch                          # List branches
git branch [BRANCH_NAME]            # Create a new branch
git branch -d [BRANCH_NAME]         # Deletes the branch
git branch -m [NEW_BRANCH_NAME]     # Renames the branch
-dis a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changesCommits to branch needs
git checkoutfollowed by the usualgit add,git commit, andgit push.
1.4.1. Switch#
Moving to another branch
git switch [BRANCH_NAME] # Move to a different branch
1.4.2. Checkout#
To merge two branches, do:
checkout
git add .
git commit -a
git push
git branch dev                          # Made a new branch called dev
git switch dev                          # Moved branches
.....                                   # After some time.... the code is ready 
git check main                          # Switch to main bringing commit history
git add .                               # Add new files
git commit -m "merging dev / main"      # Commit message
git push                                # Push changes
git switch dev                          # Go back to dev branch