Git

Git

Git is a distributed version control software system that is capable of managing versions of source code or data. It is often used to control source code by programmers who are developing software collaboratively.

 — Wikipedia

The default way to work with Git is through the command line. However, you can also work with Git using an IDE like IntelliJ or Visual Studio Code.

Even if you are working alone on a project, you can still benefit from using Git locally on your computer to track the project history.

Please refer to the official website to install Git.

Create a repository:

$ mkdir my-project
$ cd my-project/
$ git init
Initialized empty Git repository in /home/arthur/temp/my-project/.git/

Add a file to the staging index:

$ printf 'Hello, World!\n' > message.txt
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	message.txt

nothing added to commit but untracked files present (use "git add" to track)
$ git add message.txt

Create a commit:

$ git commit -m "feat: set the message"
[master (root-commit) f7b159d] feat: set the message
 1 file changed, 1 insertion(+)
 create mode 100644 message.txt

Do some code archeology:

$ git log
commit 8e426f74035c2dea8f5503bb15531a7b639180dd (HEAD -> master)
Author: Arthur <arthur@acme.com>
Date:   Tue Sep 30 14:43:48 2025 +0200

    feat: set the message

You can do the same in the IDE:

git vscode 01

Distributed VCS

Git is even more useful for collaborative work. Unlike most VCSs, Git does not require the use of a centralized repository. However, a repository can track another repository. This is called a remote repository, or simply “remote”.

Let’s create a new repository. This will serve as a reference point.

$ mkdir my-collaborative-project
$ cd my-collaborative-project/
$ git init --bare
Initialized empty Git repository in /home/arthur/temp/my-collaborative-project/

Let’s clone the repository once.

$ git clone file:///home/arthur/temp/my-collaborative-project ~/temp/my-clone-1
Cloning into '/home/arthur/temp/my-clone-1'...
warning: You appear to have cloned an empty repository.
$ cd ../my-clone-1/
$ git remote -v
origin	file:///home/arthur/temp/my-collaborative-project (fetch)
origin	file:///home/arthur/temp/my-collaborative-project (push)

We will create a file, then a commit, and push the commit to the remote.

$ printf 'Hello, World!\n' > message.txt
$ git add message.txt 
$ git commit -m "feat: set the message"
[master (root-commit) 5239aa3] feat: set the message
 1 file changed, 1 insertion(+)
 create mode 100644 message.txt
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 237 bytes | 237.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To file:///home/arthur/temp/my-collaborative-project
 * [new branch]      master -> master

Let’s clone the repository for the second time.

$ git clone file:///home/arthur/temp/my-collaborative-project ~/temp/my-clone-2
Cloning into '/home/arthur/temp/my-clone-2'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
$ cd ../my-clone-2

We will add another line to the message.txt file, create another commit, and push it.

$ printf 'Hello, Git!\n' >> message.txt
$ git add message.txt
$ git commit -m "feat: set another message"
[master 4ef854d] feat: set another message
 1 file changed, 1 insertion(+)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 278 bytes | 278.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To file:///home/arthur/temp/my-collaborative-project
   5239aa3..4ef854d  master -> master

In the first clone, we pull the changes.

$ cd ../my-clone-1
$ cat message.txt 
Hello, World!
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 258 bytes | 258.00 KiB/s, done.
From file:///home/arthur/temp/my-collaborative-project
   5239aa3..4ef854d  master     -> origin/master
Updating 5239aa3..4ef854d
Fast-forward
 message.txt | 1 +
 1 file changed, 1 insertion(+)
$ cat message.txt 
Hello, World!
Hello, Git!

The history shows the two commits:

$ git log --graph --decorate --oneline
* 4ef854d (HEAD -> master, origin/master) feat: set another message
* 5239aa3 feat: set the message