You should branch when you want to create new features or experiment with something new.
- Switch to a new branch, make & commit changes
- Switch back to master & pull from GitHub to make sure it's all up-to-date
- Switch to branch and merge master into branch
- Test to make sure everything still works!!!
- Switch back to master, merge the branch back into master, and then push back up to GitHub
What you want to do | Command |
---|---|
List branches | git branch |
Create a new branch (this creates a new branch and switches you into it) | git checkout -b <branchName> |
Switch branches | git checkout <branchName> |
Merge branches | Switch into the branch you want to merge stuff into. Then git merge <branchToMerge> |
Push branches to Github | git push origin <branchName> |
Pull branches from Github | git fetch |
Delete local branches | Switch to a branch you don’t want to delete. Then git branch -D <branchToDelete> |
Delete branches on Github | git push origin :<branchToDelete> |