DEV Community

Raymon Schouwenaar for Mr Frontend

Posted on • Originally published at Medium on

Git 101 — Step 3: branches

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 branch

Check your branches

If you want to know on which branch you are currently working? This command will tell you!

git branch

Update your local branches

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

Push to a branch

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

Switch branch

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

Do you need some help?

If your working with Git, but getting stuck? Please let me know in the comments or hit me on twitter @frontendmr and I would ❤️ to help you out!

Did you liked this post? Please share it around 🙏

Originally published at Mr Frontend Blog.


Top comments (0)