Time Travel with GIT…?

Ferdi Sungkar
4 min readMar 21, 2021
Photo by Pankaj Patel on Unsplash

Git has been a big part of developers lives, it’s widely known and used by many. But if you’re new and keep hearing about git, you’re probably wondering what exactly is git?

What is GIT?

So basically git is a version control system that helps developers to track and monitor their codes. They can go back to previous version of their code or even make different versions by branching off and doing different things, but one of the most helpful thing that makes git so useful is its ability to help with teamwork.

There are also several software or sites that can host your work by using git, the most notable are gitlab and github. Those sites can help further by helping with the continuous integration, it can automatically apply test, build, and many more into your code when pushed into the repository.

Basically git is a lot of things compiled into one system, it can be overwhelming at times but when you get the hang of it, it can really help you speed up your work.

Why use GIT?

From what I’ve mentioned git has a lot of advantages, but speaking from experience it can made you think when will I ever need that many features? Trust me after a little exploration and some eye opening moments you can really see how important git truly is.

Here are some example of when git is really useful, suppose you are working on a team and you’re given a specific task that’ll connect to all the different task at the end. If you use git all you need to do is create a new branch and work on your task there, after all the developers on your team finish their work you can all merge your work into the original branch.

source: https://github.com/dmil/code4policy/blob/master/git/06-branching.md

Another great example of when git is really useful is when you’re working on something and you’ve made a mistake, it’s pretty simple if your mistake is on one place you can just delete it. But what if that mistake is spread out on 20 different files that connected with each other, and you just want to go back to your previous version? with git you can do that easily. You’ll just need to revert back to previous commit, and you’ll feel like you’ve just time travelled because your project will look exactly like how it was, well not look like but more like it is your previous version!

Reverting is different than reseting, when reverting git actually make a new commit with the files of the previous commit. Reseting is just going back a step to the previous commit (which is dangerous).

source: https://blog.nakulrajput.com/git-revert/

How to GIT?

With all that confusing features you’re probably thinking “how to do all that?” don’t worry me too at first, but after a little learning git will get easier and easier. So I’m here to show you several basic steps to git.

Starting git

When you first start to use git, you’ll need to add your name and email to your local computer. This step will allow the git system to know your commits identity, you’ll also need to link the email and username that you choose from your computer to your git account.

git config --global user.name "<your-name>"
git config --global user.email "<your-email>"

Creating a project

You have several ways to have a git project in your local computer, the first and most common one is initializing it in your local computer.

git init

Another way to make a project in your local computer is by making a repository first on either gitlab or github site then clone that repository into your local computer.

git clone <git-remote-link>

Cloning a repository also works if you want to have an existing repository in your local computer.

Committing and Pushing

After working on your project you would typically like to store it to your repository online, to do this you’ll need several step. First add, then commit, and then push.

git add .
git commit -m "<commit-message>"
git push -u <remote-name> <git-branch-name>

or you can add and commit at the same time by using

git commit -a "<commit-message>"
git push -u <remote-name> <git-branch-name>

Changing remotes and branch

Branching is something that I’ve talked about, but I haven’t really show you how to do it. You can always change what branch you want to be in by using this command.

git checkout <branch-name>

You can also create a new branch by using this command.

git checkout -b <branch-name>

You can also delete a branch by using this command.

git checkout -d <branch-name>

Just like branches you can also change your remote, remote is basically the repository that said git is going to be committed to. To show the remote that we’re in and available we can use this command.

git remote -v

To add a new remote we can use this command.

git remote add <remote-name> <git-remote-link>

Pulling projects

If you have different people working on the same project every time someone push a new variance to the repository, you’ll need to pull it.

git pull <remote-name> <branch-name>

In conclusion git is very useful especially if you’re working on a software development field. Hopefully this article can help you understand git more and get more into git.

See you on the next article!

--

--

Ferdi Sungkar
0 Followers

A computer science student that's very new to all of this.