Git Tutorial for Beginners

Git is a powerful open-source tool that the naev game uses for its source code. It works by keeping track of changes in the code through "commits", which are like bookmaks in time that allow you to rewind your code to that point if you need to. Knowledge of git is essential to start development in naev.

.

Getting git
In a linux-based distro getting git is usually as easy as using your package manager to download and install it.

Git in Windows/MinGW
Getting git in MinGW is a bit more complicated. To do so, you need to download the .7z archive of MSysGit and extract the archive into your MinGW root. Don't overwrite.

Get a GitHub account
To do many of the things in this tutorial you need to sign up for a GitHub account. It is completely free and allows you to store your code on their servers in case of data loss. It also allows for easy "forking" of repos (explained later).

Basic commands
Fire up your command line and cd into a directory you want to start a project in.

Starting with a blank repo
To create a blank repo, so you can add code as you want, simply type:



From there, you can copy files you want committed to this folder. This will not add them to the git project however! To add some files to the next commit you need to run the following command:



Then you can "commit" these files, or create a bookmark of the state of your project, using the following command:



Leave a useful commit message so you can tell what is different from the previous commit.

Keeping track of changes
To check a list of the commits you've done a project, you can type:



To see which files are modified or new in your git directory, type:



GitHub
For naev, there already exists a git repo on GitHub, located at https://github.com/naev/naev. We'll use this as an example for the next few commands.

Cloning from GitHub
If you don't want to modify the code much, and just plan on compiling and running the latest snapshot, you can clone directly from bobbens' naev repo. To do this, find the repo on github, then find the "https clone url" along the side of the page. Use that url in the following command:



This will create a copy of the code in the current folder you are in.

Forking a GitHub repo
However if you want to mess with the code yourself it is necessary to create a fork as us commoners don't have permission to make commits to bobbens' repos directly. To fork a project, log in to your GitHub account, navigate to the repo page, and click the "fork" button. You now have an exact duplicate of the code, including all the prior commits! Now clone your newly forked naev repo in your command line the same way as the previous example, replacing bobbens' url with your own.

Pushing commits to GitHub
Pushing code to your GitHub account is also fairly simple. To do so, though, you need to give git your account name and email. Do so by entering the following commands:



Then make sure all the files you want uploaded are committed ( might help!) and enter the following command:



It will ask for your password and will upload your code for you.