Think of a branch as a tiny arrow stuck into your repository history that says I am working over here and please do not panic the main branch. Branches let you try features fix bugs or perform experiments without turning the main line into a horror show. Git stores commits once and then just hands out names to them so branches are cheap fast and basically guilt free.
A branch is a movable pointer to a commit in a Git repo. The main branch typically holds deployable code while feature branches hold work in progress. When you create a branch you are not making a copy of the whole project you are making a label that points at an existing commit. That is why creating and switching branches feels instant even when the project is enormous.
git branch
to list or create branchesgit switch
or git checkout
to move between branchesgit merge
to combine changes and preserve the branch historygit rebase
to rewrite a branch on top of another commit and make history lineargit push
to publish a branch to a remote such as GitHubRemote tracking branches keep your local names linked to the GitHub copies so collaboration does not turn into carrier pigeons and sticky notes.
Use merge when you want a clear graph that shows the join points and preserves the exact history. Use rebase when you want a tidy linear history that reads like a novel instead of a detective story. Be careful with rebase if the branch is already pushed and shared. Rewriting public history will make your teammates sad and possibly dramatic.
Expect conflicts during rebases and merges. Conflicts are normal. They are not a sign of moral failure. Resolve them locally test the result and then continue.
There are a few common approaches to branching and each has trade offs. Pick one that fits your team and stick with it unless you enjoy chaos.
Use descriptive branch names so future you and archaeology interns are not confused. Examples that do not suck include:
Make small focused commits and give them meaningful messages. If a commit is hard to explain the code probably needs a rewrite or you need better discipline.
Branches exist to reduce fear not to create more drama. Treat them as tools not fortresses and your repository will thank you or at least stop yelling in the logs.
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.