If your current branch strategy feels like a wild safari, welcome to the club. Branches are how you experiment, fix bugs, and avoid pushing half-baked features to main. This guide gives the straight facts and a little attitude while you learn how to create branches, start work, publish them, and clean up the mess when you're done.
If you want to make a branch and start working without the extra steps try one of these shortcuts. Both create a branch and move HEAD so your working tree follows along.
git checkout -b feature-name
# or the newer command
git switch -c feature-name
Use git checkout -b
if you love tradition. Use git switch -c
if you prefer clearer intent and slightly less cognitive load. Both end with you on feature-name
ready to type code and possibly regret.
Want to record a branch but stay put in your current working tree? Fine. Create the branch reference and keep working where you are.
git branch feature-name
This only writes the branch pointer. HEAD stays where it is, so your files do not change. Great for preparing branches while your editor binge compiles in the background.
Sometimes you need a branch that starts from a past commit or a release tag. Point the branch command at that reference and Git will obey.
git branch hotfix v1.2.0
# or from a commit hash
git branch bugfix abc1234
The new branch will start from the given tag or commit instead of current HEAD. This is how you make a hotfix without dragging in unrelated work.
Local branches are great until collaboration is required. Push the branch to the remote and tell Git where to track changes so future syncs are painless.
git push -u origin feature-name
The -u
option sets the upstream so later git pull
and git push
know which remote branch to use. It saves you typing and prevents awkward guessing games.
List branches and spot the stray ones that outlived their usefulness.
git branch --all
# show branches merged into current branch
git branch --merged
# delete a branch that has been merged
git branch -d old-branch
# force delete when you really mean it
git branch -D old-branch
Use git branch --all
to see local and remote branches. Use git branch --merged
to find branches safe to remove. Be cautious with -D
because it will rip out branches even when they are not merged.
git checkout -b
or git switch -c
git branch name
git push -u origin name
git branch --all
and git branch -d
There you go. You now have the commands to create branches without starting a minor civil war in your repo. Use them wisely and remember that branches are cheap but merge conflicts are memorable.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.