Git Made Simple for Everyone
A guide to learning how to use Git in the simplest and clearest way possible
This article was born from my inexperience. My first approach was through VS Code and GitHub, using the Source Control panel. After initializing the repository, I noticed that every change I made to the files was being tracked, but I didn’t know what it was for or what I could do with it.
Only later did I begin to understand and learn that this was the tool that saved my skin whenever I messed something up, while also allowing me to save my code as I implemented new features.
Then I discovered that behind those Commit and Sync buttons was Git.
Git is a system that tracks changes to files over time, allowing you to go back, collaborate, and manage parallel versions of your code.
Git is what underlies GitHub, GitLab, Gitea, Codeberg, and so on. Each of them, as well as all the others, provides various additional features that I’ll let you discover for yourself. Personally, I use GitHub for all my projects. I’ve also installed a self-hosted GitLab instance that I use for a few local side projects, but I still prefer GitHub because of how quickly it integrates with VS Code (after all, they’re both owned by Microsoft).
Let’s start with the terminology behind Git, so everything is clear from the beginning.
| Concept | Description |
|---|---|
| Repository (repo) | The project folder tracked by Git |
| Commit | A “snapshot” of the code at a given moment |
| Branch | A parallel line of development |
| Working directory | The files you are currently modifying |
| Staging area (index) | The preparation area before a commit |
| Remote | A copy of the repository on a server (e.g. GitHub) |
origin, main, and master refer to different concepts that are useful to keep distinct.
origin is the conventional name assigned to the remote repository from which you cloned the project. It is not a reserved word in Git: you can choose a different name, and the same project can have multiple remotes.
To see the configured remotes, you can use:
git remote -vmain and master, on the other hand, are branch names. Neither has any special behavior: a branch could also be called development, foo, or anything else.
For a long time, master was the default name of the first branch created by Git. Since 2020, GitHub has used main as the default name for new repositories, a choice also adopted by many other services and projects. For this reason, you can still find repositories that use master, especially if they were created earlier. This is not an error: the name of the default branch depends on the project, the platform, and your local Git configuration.
When you initialize a repository, you can explicitly choose the name of the first branch:
git init -b mainYou can check the name of the current branch with:
git branch --show-currentIn the following command, origin indicates the remote repository and main the local branch you want to publish:
git push -u origin mainThe -u option links the local main branch to the corresponding remote branch. After the first push, you can normally simply use git push and git pull without specifying the remote and branch each time.
You may also encounter the name origin/main: this is not the local main branch, but the local reference representing the last known state of the main branch on the origin remote.
I personally need to visualize things in order to understand them, so I’ll try to explain what happens from the moment you modify a file until you commit it.
Modified file -> git add -> Staged -> git commit -> Committed -> git push -> RemoteA modified file is added to the “temporary” staging area (the area where you prepare changes). Then the commit is created (with a descriptive message), and finally it is sent (pushed) to the remote (server).
Let’s move on to the main and most common commands. If you use VS Code and its native “Source Control” integration, many of these commands have been adapted into icons and text entries.
Since I work on projects as a hobby and out of passion, I rarely use Git commands in the terminal except on certain occasions for the initial setup. If I need to perform a merge or more complex actions, I rely on AI.
git init # Initializes a repo in the current foldergit clone <url> # Clones a remote repo locallygit config --global user.name "Name"git status # Shows what has been modified/stagedgit log # Commit historygit log --oneline # Compact historygit diff # Shows changes not yet stagedgit diff --staged # Shows changes already stagedgit add <file> # Adds a file to the staging areagit add . # Adds all modified filesgit commit -m "message" # Creates a commit with a messagegit commit --amend # Modifies the last commit (avoid using this on already-pushed commits)git remote add origin <url> # Links the local repo to a remote onegit push origin <branch> # Uploads commits to the remotegit pull # Downloads and integrates changes from the remotegit fetch # Downloads changes without integrating themgit restore <file> # Undoes unstaged changes (注意: irreversible)git restore --staged <file> # Removes a file from the staging areagit revert <commit-hash> # Creates a new commit that undoes a previous commitgit reset --hard <hash> # Returns to a commit, deleting everything after it (destructive)Is there more to know? Of course, but this is not the article that will explore every aspect of Git in depth. I wanted to give you an initial overview to help you understand what Git is and how to use it for basic operations.
For any further information, refer to the official documentation in English or Italian (partial).