Git Branches: A Crash Course Guide

I'm passionate about the world of software development, I never thought that I was going to understand it, but I'm glad that I challenged myself to learn it.
Search for a command to run...

I'm passionate about the world of software development, I never thought that I was going to understand it, but I'm glad that I challenged myself to learn it.
No comments yet. Be the first to comment.
Why Testing? Testing is necessary to ensure that everything works as expected. And, to be honest, we all kinda do it when we are developing. Or am I the only one who uses a bunch of console.log, print, fmt.Println or anything like that everywhere? Fo...

Classes They are the blueprint for its instances (objects that the class produce). JavaScript has had classes since the ES5 language implementations. In there it was introduced to us the native implementations of “classes” was. Typescript extends the...

GitHub Actions is a tool integrated into Github to perform tasks related to the repository given an “event”. I must give credit to this post and its Youtube video because I was of great help in this regard. If you’re in a hurry, here’s the repo conta...

It's a programming paradigm that focuses on the use of functions as a primary building block of software. In JavaScript, functional programming is supported natively, which means that you can use it without any additional libraries or tools. (And all...

YAML YAML is an information transfer language like JSON or XML. And it is used for its simplicity and consistency. File Extention These YAML files end with .yml or .yaml, either of them is correct. Indentation The indentation in YAML is essential, to...

Branches are a core feature of Git which allows us to work with different versions in parallel histories.
Note: throughout this tutorial, I’ll be using < and > symbols to show the commands, however, these symbols are not required to implement them. I just wanted to comment on it 😎. Now, let’s go with the article.
The names can’t have spaces. If you need to make a separation use symbols like: - or _.
git branch <new-branch>
You can have as many branches as you want in the repository; to switch between a branch and another there are two commands: git checkout and git switch.
Git checkout is used on many other aspects of Git besides branches; while git switch is used only for branches which decreases the margin for error and it’s the best way to switch branches.
I recommend git switch.
To change the name of the branch you’re in:
git branch -m <head-branch-new-name>
To rename a specific branch:
git branch -m <old-name-branch> <new-name-branch>
To delete branches locally:
git branch -d <branch>
git push origin --delete <branch>
And to delete a branch from the remote repository use this command:
git push origin :<branch>
Just make sure that nobody in your team depends on the changes in that branch.
git merge works to integrate the changes between branches. This integration is commonly referred to as “merge”; it keeps the branch history of “commits” intact and creates a new “commit” for the branch receiving the changes.
First, switch to the branch in which you want to receive the changes, then use the following command:
git merge <incoming-branch>
It's another way of integrating the changes of a commit history between two branches. It changes the commit history by making the integration a straight line and not a combination of branches.
Like in git merge, you have to switch to the branch in which you want to receive the changes, then use the command:
git rebase <incoming-branch>
Check which commits are in branch-b, but not on branch-a.
To check which commits are in one branch (branch-b) and not in another (branch-a) use this command:
git log <branch-a>..<branch-b>
You can also use it to compare them with the remote branches.
It was a short post but I just wanted to challenge myself to write so I told myself that I was gonna do this no matter what, so here it is. I hope I was useful to you.
That’s it for me, but you can follow me on LinkedIn, Twitter, Instagram, Facebook, Github, Reddit and here in Hashnode. Also, you can subscribe to my newsletter down below 👇. Well, see ya!