Super Basic Git Starter

This page is a WIP. I plan on updating it time-to-time. You noticed a mistake? Send me a mail at luka [at] ljudi [dot] org. Cheers!

What is git?

Git is a FOSS distributed version control system.

Or, to put it simply, a tool to keep a track of changes on your projects (mostly programming projects, but git works on non-text files too).

Show me

First - install git. On Arch (if you use paru), you can just run paru -S git.

Then create a directory for your project and initialize the git repository inside of it.

$ git init
$ git config user.email "torvalds@linux-foundation.org"
$ git config user.name "Linus Torvalds"

An alternative would be to clone a repository from a remote device (github for example); in that case you would use git clone <url> instead of creating a directory and running git init inside of it.

This sets up a git repository in your project directory. Now you can start creating files, editing them, and so on.

Then you can create a repository on some git forge, like github or codeberg. When you do that, you will get an url that will point to that repository. Now you need to set the remote url of your local project to that remote repository.

You don’t need to do this if you cloned a directory.

$ git remote add origin <url>
$ git branch -M main

Now, after you stage and commit your changes, you can push them to the remote repository.

$ git add .
$ git commit
$ git push -u origin main

That’s about it, at least for the start.

Stage!? Commit?!

If you are confused by some terms I mentioned, let me try to explain some things.

At every moment, there are 3 ’trees’ in your git project:

  1. working directory : holds actual files
  2. index (stage) : staging area (tree with changes)
  3. HEAD : points to the last commit
$ git add .
$ # adds all files from the $(pwd) to the staging area
$ git add <filename>
$ # adds only a specific file to the staging area
$ git commit
$ # creates a 'snapshot' of the project

And as for git push:

What about configuration?

I prefer adding a name and email separately for each project (io. not having a global email and name), so I can handle multiple accounts more easily.

And this is my tiny git config (stored in “$XDG_CONFIG_HOME/git/config”)

[core]
    editor = nvim
[init]
    defaultBranch = main
[color]
    ui = true

Closing notes

If you are reading this, it means that the article is not fully done. The following is a list of topics that I plan to cover in the foreseeable future.

Stay tuned! Cheers!

Previous I'm feeling lucky! Next