Git: Let’s Collaborate!

FADHIL IBRAHIM
5 min readMar 21, 2021

In the software development industry, collaboration is a must. By collaborating, something complex can be done easily. With multiple individuals working on a project, the task can be broken down equally into small pieces into some specific tasks and then assign it to different person. By doing this, the development progress will become more efficient.

To collaborate on a project, a developer certainly needs to be aware not only of what he is doing, but also what other team members are doing. The purpose is to find out what increments that have been made so we can adjust what we are working on with these increments. Developers also need to save the old version of their works so if something bad happen in the future, or they have a bug just in the older version, they can fix it easily.

Therefore, developer needs a good collaboration tools to support their job. So, what are the best collaboration tools a developer can use? Let me introduce you with Git!

Git Logo taken from https://id.m.wikipedia.org/wiki/Berkas:Git-logo.svg

What is Git?

Git is a distributed version control system that designed to handle all kind of projects (whether it is small or big) quickly and efficiently.

What is version control?

Version control is something that we can use to track and managing changes in the software code. With this tracking ability, whenever we made a mistake in the development phase, we can turn back to the earlier version of the code then compare it to fix the problem.

Git also has the better functionality, performance, security, and flexibility that most developers need. So, that is why Git is the most favorite version control for developers for collaborating.

How to Work with Git?

To know deeper about Git, we should give it a try:). Git has so many command line utilities that we can used to track and record changes in our code. To use git for collaboration. Here are some command line utilities that you can use.

Git Clone

Suppose your team has already made a new project with a repository and you want to contribute with it. The first thing that you have to do is clone that repository into your computer. You can do it by execute this command.

git clone [repository's url]

This is the example of using git clone.

The example of using git clone

Git Pull

Suppose one of your mate has already push an update on a branch and you want to bring those updates into your working directory in your computer. You can execute this command.

git pull origin [branchname]

Git Remote

When we first clone the repository to our local working directory, we automatically get a remote called origin. You can simple see it by executing this command.

git remote

But actually, this remote has two entries, for pulling changes down (fetch) and push. But they have same url. Why? It is simply because they pull and push changes to the same repository. You can see it by executing a verbose command.

git remote -v
The difference between remote and remote verbose

Suppose you want to make this remote become more descriptive. You can change the remote name by simply executing this command.

git remote rename [newname] [oldname]

Then, suppose you want to add an additional remote to push to another remote repository because you collaborate with someone who doesn’t have the access to the original repository. Or maybe you want to migrate the repository to the other remote server. You can simply execute this command.

git remote rename [remotename] [repository's url]
The example of using git remote add

Git Push

Suppose you are already done with your code and you want to update it into some branch of your project repository. You can simply execute this bunch of command.

git add .
git commit -m "commit message"
git push origin [branch]
The example of Git Push

Git Merge and Git Rebase

Suppose your repository have 2 branches, master and feature. Your current branch is feature. At some time, you already finished with your code and you want to integrate it to master branch. You can do with with two ways, merge or rebase. These two methods have a same purpose but different characteristics. Both of them have pros and cons between one and another. Merge has a simpler command to execute. But in the end, the result makes it more difficult for us to keep track of the commit history. It is simply because merge preserves the branch history.

Git Merge Ilustration. Image from atlassian.com

In the opposite direction, rebase has more steps of command. But this method clear the commit history from the source branch so we can track the commit in the target branch easily.

Git Rebase Illustration. Image from atlassian.com

To integrate branch using git merge, first you can go to the master branch using git checkout, then merge those branch using git merge. Here are the commands that you can use to perform this action.

git checkout master
git merge feature

And to integrate branch using git rebase, first, go to your branch, perform git rebase and use master as a target, checkout to master, and then merge it. Here are the commands that you can use to perform this action.

git checkout branch
git rebase master
git checkout master
git merge branch

Git Stash

Suppose you want to put your changes aside when you want to switch to another branch and then bring back this changes when you ready to working on it again. You can simply execute this command.

git stash -u

Then, if you want bring back this changes. You can simply execute git stash list, then it will show all of your stash. After that, you can choose the changes that you want to bring back then execute git stash apply [number].

Conclusion

Git has so many features that can we used to collaborate. All the commands that I said in this article earlier were only the basic commands from git which actually have more variations. You can go checkout the git documentation to see more interesting commands.

So, let’s collaborate with Git!

References

https://www.atlassian.com/git/tutorials/merging-vs-rebasing#:~:text=Merging%20is%20a%20safe%20option,onto%20the%20tip%20of%20master%20.

--

--