Sneak Peek About Git

Taufik Algi
4 min readMar 22, 2021
https://www.techrepublic.com/article/how-to-install-git-on-android/

Have you ever thought about how software is made? How is the developer working together making the software? Merging line by line of code? That sounds terrible if you do that manually. Therefore, git is there to solve the problem.

What is git?

Git is one of the VCS (Version Control System) that is popular among developers right now. In git, every work that is done by developers is combined in the same repository. Not only for the latest version of the software but also the full history of all changes. Therefore one of the problems that made it difficult for developers to work together was resolved thanks to git.

So how to use git?

Before you use git, make sure to install git CLI first. On Linux, you can install git by using the following commands.

$ sudo apt-get update
$ sudo apt-get install git

Configure your git username and email using the following commands

$ git config - global user.name "Your Name"
$ git config - global user.email "Your Email Address"

Git Commands

After finishing the installation, there are two ways to connect your git repository and local repository.

Pushing your local code to an empty repository
On your terminal:

$ cd your_local_code_folder
$ git init
$ git remote add origin link_to_your_git_repository
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master

With that, now you can access your code from another PC that is connected to the internet.

Cloning an existing git repository to your local
On your terminal:

$ git clone link_to_your_git_repository
$ cd your_repository_name

Now you can make changes and push the changes to your git repository.

Of course, your problem does not end there. There are still many git commands that you should know. When working together, there is still a possibility of conflicts in the code that you and your team created. For example, conflict can happen when there are two different codes in the same file that were created in the different branches, and you merge those two branches. Or when you make changes to a file, and you pull the recent code from the git repository, and it turns out that your friend already made changes on it. With these following commands, hope you can avoid possible problems that occur.

Pull

Pull used to incorporate changes from a remote repository into the current branch on your local repository. In fact, pull is a shorthand for git fetch followed by git merge FETCH_HEAD. Using this single command is equivalent to those two commands.

Push

Using this command, you can update your remote repository using your local repository by sending the necessary changes.

Clone

By using this command, a new directory will be created based on the remote repository. This command will also create remote-tracking branches for each branch in the cloned repository.

Merge

If you have two different branches (e.g. master and staging), you can incorporate those two different branches by using the merge command.

Rebase

At first glance, this command might look like the merge one, but it is actually different. This command either moves or combines a sequence of commits to a new base commit.

https://code.tutsplus.com/tutorials/rewriting-history-with-git-rebase--cms-23191

Revert

By using the revert command, you can revert any changes and record some new commits. Before using this command, make sure your working tree is clean or no modifications from the HEAD commit.

Stash

When you already made changes on your local repository, but you want to go back to a clean working directory (that no changes yet on the local repository), stash is the solution to your problem. This command saves your modifications away and reverts the working directory to the latest HEAD commit that already committed.

Remote

With this command, you can manage the remote repository which is connected to your local repository.

Checkout

This is one of the branching git commands. With this command, you can move to an existing branch or create a new branch.

Branch

Just like the name, this command used to manage the branch. With this command, you can see existing branches that exist both on your local and remote repository.

That is a little sneak peek about one of the Version Control Systems called git. Have a nice day!

References

--

--

Taufik Algi

Undergraduate student of Computer Science at Universitas Indonesia