DevOps••12 min read•12 views

Git Guide for Beginners: Understanding, Install & Configure

Learning Git doesn't have to be a headache! Find the meaning of Git, main functions, and a complete tutorial on how to install Git on Windows, macOS, and Linux for beginners.

Git Saves Lives from the "Final_Code_Last_Revision_Really" Tragedy

Have you ever worked on a project, whether it was making a website, application, or just writing a long document, and then you were really afraid to change something that was already running? Finally, to be safe, you copy the project folder and give it a different name. Starting from Initial_Project, continue adding features to Project_Fix, there is a small error you fix it and save it to Project_Fix_Banget, until finally your folder is full of magical names like Project_Udah_Beres_Tinggal_Kumpul_Sumpah.

Let's be honest, we've all been in that phase. This manual method may seem easy at first, but just imagine if the project gets bigger. Especially if you start working with other people. Imagine you and your friend editing the same file, at the same time, and then you have to combine your code manually. What a headache, right? Just copying one line wrong, the application that was running smoothly suddenly crash and you don't know where the error is.

Well, this is where Git comes in as a hero without a cape. If you want to be serious in the world of software engineering or development, understanding Git is absolutely obligatory. So, let's chat casually about what Git is, why you really need this tools, how to use it, and how to install it on your laptop, whether it's Windows, Mac, or Linux.

What is Git, anyway?

If you want to use somewhat technical language, Git is a Version Control System (VCS) which is distributed or distributed. But since we're having a casual chat, let's use an analogy that's easier to digest.

Just pretend this Git is time machine and CCTV create your project folder.

Every time you write new code, add a feature, or delete a file, Git will record all the changes. He knows who changed it, what was changed, when it was changed, and why it was changed (via the message you wrote). If suddenly today your code has a serious error and you don't know how to fix it, you can just "rewind" using the Git time machine to yesterday's condition when the code was still running normally. Magical, right?

Git was originally created by Linus Torvalds (the father of the Linux operating system) in 2005. At that time, he needed a system to manage the Linux kernel code which was being worked on by thousands of people from all over the world, but he was not satisfied with the tools that existed at that time. Finally, in true programmer style: if you don't have a good one, just make your own. Become the Git we use now.

One important thing that people often misunderstand: Git is DIFFERENT from GitHub, GitLab, or Bitbucket.

Many beginners think that Git and GitHub are the same thing. Here's an analogy: Git is the engine, the system that runs on your laptop to create real code history. Meanwhile, GitHub is an online garage where you store your cars (projects) so they can be seen or shared with other people from all over the world. You can use Git without internet at all on your laptop, but if you want to show off your code to other people, then you upload to GitHub.

Why do programmers really need Git?

Maybe you're thinking, "Ah, my project is still small, I'm coding alone, why bother learning Git?"

Wait a minute. The benefits of Git are not only for teamwork. For solo developer, Git is like safety net or a safety net when you're playing the circus.

  1. Free to Experiment (Branching)

    Have you ever had a crazy idea to add a new feature to your application, but were afraid that the code would break existing features? In Git, there is a concept called Branch. You can create a kind of alternate universe or parallel world from your project. In this parallel world, you are free to mess around with the code, add feature A, delete feature B. If it turns out that the experiment failed miserably and actually created an error, you just delete branch and go back to branch (usually called main or master). Your main code remains safe and sound without the slightest scratch. If the experiment is successful? Just merge (merge) into the main code.

  2. Tracking Who is Throwing a Tantrum

    If you work as a team, Git will reveal in great detail who changed a particular line of code. So if a bug appears, you can find out exactly who the culprit is via the command git blame (the name alone is very provocative: blame or blame). But the aim is not to fight, but to ask the person, "Hey bro, what do you mean by writing this function? Because it's causing an error on my part."

  3. Project Journey Documentation

    Every time you save changes in Git (the term is Commit), you are required to write a short message. For example: "Added Google login feature" or "Fixed the bug that the submit button couldn't be clicked". From this series of messages, you or other programmers who read your code will be able to understand the flow of thought and the history of the project's evolution from zero to a large application.

Preparing for War: How to Install Git

Okay, now we get to the technical part. Because people's operating systems are different, installation methods are also different. Don't worry, installing Git is one of the easiest and rarely causes problems.

1. Git Installation on Windows

For you Windows people, you have privilege to get an additional software called Git Bash. This is very important because the default Windows command prompt (CMD) is sometimes not very convenient to use for carrying out Linux-style commands. Git Bash will give you a terminal that feel is very similar to the terminal on Linux or Mac.

  • Step 1: Open a browser and go to the official Git website at [https://git-scm.com/download/win](https://git-scm.com/download/win).

  •  

  • Step 3: Open the .exe file that was downloaded earlier.

  • Step 4: Well, here you will find lots of options when you click Next. My advice for beginners: Just click Next until it's done, leave everything in the settings default (default). Their default settings are the most optimal and safe for 99% user.

  • Step 5: Once finished, try right-clicking in any folder or on the desktop. If the installation is successful, the option "Open Git Bash here" will appear (if you are using Windows 11, you may have to click "Show more options" first).

2. Git installation on macOS

For Mac users (especially if you often code or use tools like Docker or Orbstack), usually you already have a fairly powerful terminal. There are several ways to install Git on a Mac, but these are the two most common:

  • First Way (Automatic from Apple):

    Open the Terminal application. Just type the command git --version then press Enter. If Git is not installed, the Mac will display a pop-up that offers you to download and install Command Line Developer Tools (this is a package from Xcode). Just click "Install", wait until it's finished, and you're done.

  • Second Method (Use Homebrew):

    If you are a software engineer using a Mac, chances are you are already familiar with Homebrew (a package manager for Mac). This is the most recommended method so that your Git can always be easily updated to the latest version.

    Open Terminal, then just type: brew install git. Wait for Homebrew to do its job, and voila, Git is installed.

3. Git Installation on Linux

Linux and Git are like siblings (which makes them both Linus Torvalds), so installation is really easy via your OS's built-in terminal.

  • For Ubuntu / Debian / Linux Mint users:

    Open a terminal and type:

    sudo apt update

    sudo apt install git

  • For Fedora / CentOS / RHEL users:

    Type this in the terminal:

    sudo dnf install git (or use yum if it's an old version of Fedora).

  • For Arch Linux users:

    Type: sudo pacman -S git

After the process on any OS is complete, make it a habit to check whether Git has actually appeared on your computer. Open a terminal (or Git Bash on Windows) and type:

git --version

If something like git version 2.x.x appears, congratulations! You are ready to enter the real world of Git.

Initial Configuration (Don't Miss It!)

This is the part that beginners often skip, even though it is really crucial. After installing, you have to introduce yourself to Git. Why? Because as I said earlier, Git really knows who made the changes. If you don't set your name and email, Git will protest and won't carry out your commands when saving data.

Open your terminal or Git Bash, then type these two command lines (replace with your real name and email):

Bash
git config --global user.name "Your Cool Name"
git config --global user.email "[email protected]"

Important note: The email you enter here does not have to be the email installed on your GitHub account, but it is highly recommended to just match it. The problem is that later when you push (upload) your code to GitHub, GitHub will check this email to display your profile photo and name in the list of project contributors.

Apart from identity, there is one more configuration that I think is quite important to set at the beginning, namely determining the name of the main branch. In the past, Git used the name master as default. But recently, the software industry agreed to change the term to main to be more inclusive. So that your Git automatically uses the name main every time you create a new project, type this:

Bash
git config --global init.defaultBranch main

To make sure all your configurations are correct, you can check using the command:

Bash
git config --list

If your name and email appear on the list, it means you are ready to fight.

Basic Everyday Git Workflow

Now, how do we actually use Git while we're working? Try to imagine that you want to create a new project folder, for example a web application. The Git workflow actually goes back and forth in this cycle: Init -> Add -> Commit. Here's the story:

1. Enable Git in Folder (git init)

You create a new folder, just call it web-portfolio. This folder is still a normal folder. In order for Git to start monitoring this folder, you have to enter the folder via the terminal, then type:

Bash
git init

This command tells Git, "Hey Git, please monitor all the files in this folder from now until later." Git will create a hidden folder called .git. Well, the .git folder is the brain of your time machine. Don't ever delete it, okay!

2. Selecting the file you want to save (git add)

Let's say you just created a file index.html and wrote the outline of the website. This file has changed, but Git has not saved the changes permanently. Git has a "double confirm" system. You have to put the changed files into a waiting area (its name is Staging Area).

To do this, type:

Bash
git add index.html

If you change a lot of files and don't feel like typing their names one by one, you can enter them all at once using dots:

Bash
git add .

The dot means "all changed files in this folder and in its sub-folders".

3. Saving the Journey (git commit)

After the file is in the waiting room, it's time to "snap" it, aka save its condition permanently in Git history. This process is called Commit. You must give a short message about what you are doing.

Bash
git commit -m "Create the initial HTML structure for the home page"

The letters -m there mean message (message). Try to write a commit message that makes sense and is clear. Don't write messages like "update", "fix", or "asdfgh". Believe me, writing a clear message is a form of affection for yourself in the future (when you have to reread the code in 3 months).

4. Ngecek Status (git status)

Di tengah-tengah kerja, kamu mungkin lupa file mana aja yang udah di-edit dan mana yang udah dimasukin ke ruang tunggu. Di sinilah kamu pakai:

Bash
git status

Perintah ini bakal ngasih tahu kamu semuanya dengan bahasa yang (lumayan) manusiawi. Warnanya juga biasanya beda, kalau merah berarti filenya diedit tapi belum di-add, kalau hijau berarti udah di-add dan siap di-commit.

5. Ngeliat Sejarah Masa Lalu (git log)

Setelah kamu kerja berhari-hari dan melakukan banyak commit, kamu bisa ngelihat catatan perjalanan project kamu pakai:

Bash
git log

Di situ bakal kelihatan urutan waktu, siapa yang commit, pesan commit-nya apa, dan kode unik (hash) dari masing-masing commit. Kode unik inilah yang nanti bisa kamu pakai kalau kamu butuh time travel balik ke masa lalu.

Tips Tambahan Buat Survive di Dunia Git

Sebagai penutup, ada satu best practice yang wajib banget kamu tahu sejak hari pertama belajar Git, yaitu penggunaan file .gitignore.

Sebagai developer, pasti ada file atau folder yang NGGAK BOLEH dilacak sama Git atau diupload ke GitHub. Contoh paling nyata kalau kamu pakai Node.js atau React adalah folder node_modules (ukurannya bisa segede gaban dan isinya cuma library doang). Atau kalau kamu bikin aplikasi yang konek ke database, file .env yang isinya password dan konfigurasi rahasia juga haram hukumnya buat dilacak Git, apalagi sampai bocor ke publik.

Solusinya? Kamu cukup bikin file baru dengan nama persis .gitignore (pake titik di depannya) di folder utama project kamu. Terus di dalam file itu, tulis aja nama folder atau file yang mau kamu cuekin.

Misalnya isi file .gitignore kamu:

Plaintext
node_modules/
.env
secret-key.txt

Dengan begitu, mau kamu ketik git add . sampai seribu kali pun, Git bakal merem dan pura-pura nggak lihat file-file yang ada di daftar itu. Komputermu aman, rahasia database-mu aman, dan temen kerjamu nggak bakal ngomel karena kamu nge-upload folder ratusan megabyte yang nggak penting.

Kesimpulannya...

Belajar Git di awal-awal mungkin kerasa ribet banget. Kamu yang tadinya tinggal tekan Ctrl+S sekarang harus repot-repot buka terminal, ngetik git add, git commit, dan pusing sama branch. Belum lagi kalau nanti kamu belajar soal merge conflict (saat dua orang ngedit baris yang sama dan Git bingung harus milih yang mana).

Tapi percayalah, learning curve atau masa-masa susah belajar Git ini sepadan banget. Begitu kamu udah terbiasa, workflow ini bakal masuk ke muscle memory (ingatan otot) kamu. Jari kamu bakal otomatis ngetik git status tiap kali buka terminal.

Git itu ngasih kamu kebebasan buat bikin kesalahan tanpa rasa takut. Kamu bisa ngulik kode segila apapun, nyoba-nyoba framework baru, atau merombak arsitektur database kamu, dengan perasaan tenang karena kamu tahu kamu selalu punya tombol undo super canggih yang bisa ngembaliin semuanya seperti semula.

Jadi, buat kamu yang masih nyimpen folder dengan nama Sistem_Informasi_Final_Revisi_Dosen_Banget_Fix.zip, ini saat yang tepat buat hapus kebiasaan itu, buka terminal kamu, ketik git init, dan mulai ngoding layaknya software engineer profesional. Semangat ngoprek....!

Sigit Wasis Subekti

Sigit Wasis Subekti

Software Engineer & Tech Educator

Software Engineer and Tech Educator sharing insights on web development and software architecture.