This time we are going to talk about how you can handle branches with Git on the terminal 🚀. For a full explanation check the video 😉
What is a Git branch?A branch is a separate workspace, it’s like a bucket where you can fiddle around without screwing the production application.
You create branches when you are gonna make new functionality or features for your application.
So let’s get started with branches!
Check your branchCheck your branches
If you want to know on which branch you are currently working? This command will tell you!
git branch``` <strong>Update your local branches</strong> So let's face it! Sometimes your branches are behind of the branches on the remote. So to update this list, use this command.
git fetch origin```
Do something with your branch!Create branch
Now we want to create a branch, because we want to fiddle around without the code. Pretty easy command. Keep in mind to use "-b" instead of the "-d"!! 😅, because the "-d" will delete your branch!
git checkout -b branch_name``` <strong>Push to a branch</strong> When you made some changes, staged them and added a commit message, we want to push our branch to the remote. Use this command for it!
git push origin branch_name```Pull changes from a branch
When your team member made some change to the same branch you are working on. You can pull those changes from the remote into your local branch with this command.
git pull origin branch_name``` <strong>Switch branch</strong> Sometimes you want to switch to another branch for some reason. Just checkout the other branch with this command.
git checkout branch_name```Delete local branch
Be careful with this command! If you didn't pushed the changes in this branch, all the changes will be lost with this command!
git branch -d branch_name``` <h2>Do you need some help?</h2> If your working with Git, but getting stuck? Please let me know in the comments or hit me on twitter <a href="https://twitter.com/frontendmr" target="_blank" rel="noopener">@frontendmr</a> and I would &#x2764;&#xfe0f; to help you out! Did you liked this post? Please share it around 🙏 <div class="grammarly-disable-indicator"></div>