Git 101 (for dummies)

Darren Ngoh
4 min readMar 1, 2022
Branching Timelines in Loki (https://www.looper.com)

a git pull a day keeps the conflicts away!

Imagine you’re five years old doing your coloring homework from the nursery. You’ve colored all of the leaves green, but you just realized that it is currently Fall. With Git, you can revert all your choice of green within clicks or even put the green-colored version to a different branch called ‘Spring.’ In short, Git makes all actions recorded and reversible.

If you are a computer science freshman or just someone who just started programming and wants to try using Git, this article is for you! We will cover all the primary usage of Git and get you started Git-ing in no time.

Getting started with Git

First of all, to use Git you have to have Git installed. You can check whether you have it properly installed by entering the following command on your terminal for macOS and Linux users, or cmd for Windows users:

git --version

You can head here for macOS installation, here for Windows installation, and here for Linux. Note that those links will get you to the official Git website and you can have the GUI-enabled installer to help you. If you’re using a Unix-based OS you can easily install git using Homebrew by entering the following command:

brew install git

The next step is to setup your Git account on your local machine. You will have to provide your username and email using git config.

git config --global user.name "darren"
git config --global user.email "darren@email.com"

You can again check both username and email with the following command:

git config user.name
git config user.email

Your first repository!

Git is all about having a repository stored locally or in the cloud. GitLab and GitHub is the two most common Git Management System. They are Google Drives for Git repositories.

With that being said, there are 2 main ways of starting your first repo. First, you can create a local git repository by entering the following command:

git init

Beside initiating your own repo, you can also clone repo(s) online by using:

git clone [repo_url]# example
git clone https://github.com/uasoft-indonesia/badaso-lms-theme.git

There is various ways of cloning a repository online, the one above is the easiest or most common by using HTTPS. You can also use SSH or CLI provided by some of the platforms.

The Mantra

These are the bare minimum you have to know for using Git.

git add [file(s) / folder(s)]
git commit -m "commit message"
git push [remote] [branch_name]
  1. Add
    This command adds file(s) or folder(s) that you want to include in your current version of the repo. For instance, you have finished developing an authentication feature, to “save” your progress you have to add all the files that you made changes at.
  2. Commit
    Upon adding the related files, you have to commit your changes. Commit made a new version of your repo, and keep in mind that “new” here doesn’t always translate to “new”. If you revert your progresses, you still have to commit again, making it not “new”. Commits are followed by commit message, this makes us easier to distinguish commits from one another. Commits are better done per progress as it won’t be useful when we want to revert to certain step.
  3. Push
    Once you’ve committed, you can now push your commits to remote/online repositories for others to access or pull.

Git for collaborating

Collaborative working is made very easy with the help of Git. It allows developers to track changes especially to codebases. Git is a mush-have for programmers as it ensures speed, data integrity, non-linear workflows that really helps programmers to publish, document, and maintain versions of data.

git pull [remote] [branch]

Git pull merges updates from your remote repository to your local repository. Let’s say you’ve made changes on your Macbook Pro M1 and pushed to GitHub. Unfortunately, you lost your Macbook, and decided to use your ASUS ROG instead, the progress on your ASUS will not be synced to your remote repo before doing the necessary pull.

git branch [new-branch]

Next, branching. Branching enables multiple people working in a same repository simultaneously It minimizes the possibility of conflicts. Conflicts is when more than 1 people are editing the same line of code. The above code snippet will create a new branch locally.

git branch -d [branch]
git branch -a

Adding a d or a flag after the word branch will delete the specified branch and list all existing branches respectively.

git checkout [branch]
git checkout -b [new-branch]

Checkouts are branchings’ best friend. You use git checkout to switch branches. Adding the flag b will create a new branch and immediately switch to it.

git status

You can check your current progresses, which branch are you currently in, list of files created, modified, or deleted with git status.

This has been Git 101 for dummies. This is very useful if you are just starting out in Computer Science at university. These git mantras alone got me through second year. Here at the Faculty of Computer Science, University of Indonesia, we are used to using Git for collaborative task or assignment.

We at Software Engineering Project or PPL, leverages GitFlow to the fullest when it comes to working together in a team. We do different branches for each Product Backlog Item (PBI), it is to minimizes conflicts between different developers. Beside branchings, We do beautiful commit messages, co-op code reviews, pull requests, and many more. Git plays a crucial role in our team’s collaboration. We are often tasked with overlapping and highly dependent on each other making Git and GitFlow methodology our go-to, our 24/7.

--

--