Teamwork via Git

2 minutes read

You can understand a teamwork process through Git using my example.

Note: If you do not have basic knowledge of git and do not understand what this article says, please review the previous articles about your git.

Example: You are assigned to fix bugs iss53 for a company project and another person fixes another bug in the project. So how can two people code together quickly and conveniently?

To make it easy to understand, I will specify the names of the two people are A and B.

When A fixes bugs iss53, according to the process A will have to create a new branch.

$ git checkout -b iss53
Switched to a new branch "iss53"

Now the main branch of the company looks like this:

Person A does something and makes a commit on the iss53 branch.

$ git commit -a -m 'added a new footer [issue 53]'

Somewhere else, Person B does the same thing that Person A did to create a new branch named hotfix and do something and then create a commit on the hotfix branch.

$ git checkout -b hotfix
Switched to a new branch 'hotfix'
$ vim index.html
$ git commit -a -m 'fixed the broken email address'
[hotfix 1fb7853] fixed the broken email address
 1 file changed, 2 insertions(+)

After thoroughly checking their patches, person B decided to merge the hotfix branch with the company’s main branch by running the git merge command and then using git push to push it onto the git server of the company.

$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
 index.html | 2 ++
 1 file changed, 2 insertions(+)
$ git push

Now the main branch of your company will look like this:

Once the merge is complete, you can delete that branch because it’s not important right now.

$ git branch -d hotfix
Deleted branch hotfix (3a0874c).

Now go back to person A, because person B has done their work and has pushed it onto the company’s git server so person A needs to use git pull to pull the code back:

$ git checkout master
Switched to branch 'master'
$ git pull

Then move on to the iss53 branch and use the git rebase command to merge the master branch into the iss53 branch and continue the work and make another commit on the iss53 branch:

$ git checkout iss53
Switched to branch 'iss53'
$ git rebase master
$ git commit -a -m 'finished the new footer [issue 53]'
[iss53 ad82d7a] finished the new footer [issue 53]
1 file changed, 1 insertion(+)

Suppose that person A decides that the work on iss53 branch is completed. Person A will checkout the master branch and use the git rebase command to merge the iss53 branch with the master branch:

$ git checkout master
Switched to branch 'master'
$ git rebase iss53

And finally delete the iss53 branch:

$ git branch -d iss53

Finally, push the code to the company’s git server:

$ git push

Good. So you’ve learned how to work in groups with others.


Categories: Learn programming

Keywords: Git
Comments