The Developer Quest

The Developer Quest

Branches in Git

Branches in Git

Let's explore the most basic feature of VCS, i.e. the branches

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Branches are no doubt, one the BEST features of Git. The Master Branch being the default of the repository is automatically created whenever you fork a new repo. So usually when making commits, we've being committing only to the master branch. This master branch is the stable version of your code and something you will release that's the reason why we don't really want to try out new code or features on this stable version (master branch) just in case it messes the whole code of your repo. So we create an isolated space to experiment new code and features. If all goes good and they seem to work well, you can merge this isolated space (i.e branch) into the master branch thus eliminating the risk of messing up with the stable version of your repo.

This is why branches are a massive feature. Saving you right?

##Working on a branch Here's how you can work on branches:

1) Make a new branch git checkout -b <branch name>

If you want to switch to an existing branch use git checkout <branch name>

2) Open the editor of your choice and make changes

3) Add the files git add .

4) Commit the changes and add a commit message git commit -m "commit message"

5) Finally, push these changes to the origin git push origin

If error occurs, it's probably because you've not set your remote properly . Try using git remote set-url origin SSH of your repo OR git push --set-upstream origin <branch name>

Congrats! You've merged your branch into the master!

##Deleting a branch

git branch -d <branch name>

Also delete branch from origin using

git push origin --delete <branch name>

[This article is contributed by our Senior Frontend Developer Miss Kulsoom , Thank you Miss Developer 🤗]

#git#github
 
Share this