Implement nice teamwork with Git and Github(2)

Francabel
4 min readMay 4, 2020

In the previous article, we have gone through some basic but powerful Git command line. In section 2, I would like to share the concept of branch and you will see Git’s real power in collaboration.

Branch is not tree branch (git branch -v/git branch “branch name”)

Why do we need the concept of branch? The above photo illustrates the difference between linear and branch development. The feature C is new feature which you have not done yet and it can not be launched. But there is problem (A fixed) you need to solve. In the linear development, the feature C might be leaked accidentally.

However, in branch development, the whole development will be divided into two parallel steps, one is for new feature development, the other is for problem solving. So, when new feature is being developed, you can fix the problem simultaneously and do not worry about leak of new feature.

In git, you can use git branch -v to check how many branches you have currently and create a new branch by git branch “branch name”.

Switch to different branch or commit (git checkout “branch name”)

From the previous step for creating a new branch, now you may wonder what if I would like to switch to another branches or the master. We can use git checkout “branch name” to switch to the branch you want. It also can transfer the commit number as the following photos. We transfer our git from edited to unedited.

The difficulty from merge — conflict (git merge)

Let’s say that the project is in the final stage and now you want to combine every branch to the master channel. So, you can switch to master and use git merge to combine branch to the master. But there is always a but. If you do some changes to part A on the master and your colleagues make change to part A on the branch. When you merge them, the conflict will happen and say “automatic merge failed” because git does not know where version of change you want to leave or remove. So, we have to manually revise it and commit this change.

So, now the branch has already been merged in the master. after merging, you can delete the branch you just merge into the master.

Change the branch name (git branch -m “new name”)

If you want to change your branch name, you just need to type git branch -m “new name”

Git is quite useful in multiplayer teamwork. Good version control and management can help you save time from back-and-forth check. Meanwhile, Git can also solve the issue that you faced in the linear development.

If you like my article and it is useful for your Git learning, please click “like” and share to other people. Thank you!

Reference to Lidemy

--

--

Francabel

從業務轉換跑道,目前正朝著前端工程師邁進,寫code是生活,是工作,也是態度。轉職是一段旅行,享受旅行的過程,並指引到夢想處