Branches
Work with branches is essential to have an organized project. Learn about how to work with them is one of the first things when we talk about git and versions.
So, why should I use branches?
When you create a new feature or add an update in your code, it is a good practice create a new branch, that is a copy in certain point of the master code. We do this to keep on master only the tested and refactored code.
In the image below, the master is represented with the blue color, and the branches with purple and green. The purple branch can symbolize a branch to fix a problem and the green one a new feature, for example.
Now you can safely work in your code, doing all the necessary changes without having to redo your code on master if something gets wrong, or if the code it's not in the final version yet.
You can note that in the image the master branch seems to have some commits ahead of the other branches. This happens mostly when you are working on collaborative projects. In this post we'll focus only in the branch concept, letting the idea of rebase and merge to another post.
Create and use branches
git branch: to list your branches and also see your current branch;git branch <branchName>: to create your branch;git checkout <branchName>: to go to the branch that you want.
git branch. You'll probably see only one branch, named main, that is your master code. If you want to create a new branch you can just use git branch <branchName> and later go for your branch using git checkout <branchName>.🧰 QGit: a great tool to manage your branches
When we start to create branches, rebase and work with remotes repositories, especially on larger projects, we can get confused about where is our branch based, if our remote repository is updated with local or where are we on main.
sudo apt install qgitqgit &
Comments
Post a Comment