Setting up Git

Intro

Git is an essential tool in the modern developer's toolkit. Not only is it invaluable in keeping track of personal projects, it has also become a requirement for collaboration with other programmers.

Download and install

Many linux distros will have git pre-installed. Use 'git' in your terminal to make sure it is installed on your system. If not, it should be in the defualt repos of the major package managers.

If you are on Windows, you will want to head to the downloads page of the git website. Download and click through the installation wizard. Now you should be able to find a program called "Git Bash" on your computer, open it and you are in business!

Configure git

Enter the following commands to configure the name and email that will be associated with your commits:

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

Initialize repository

Open your terminal (or Git Bash if you are on Windows) and navigate to the folder you want to make into a repository. For example, if my path is /home/cory/MyProject the respository would include every file inside the MyProject folder. Now go ahead and initialize the repo with the following command:

$ git init

First commit

Now that you have a respository initialized in your current directory, it is time to commit the files that are already there! Enter the following commands to add all the files in the directory to your repo and commit:

$ git add .
$ git commit -m "First commit!"

That is all! You have now successfully installed and configured git, and initilialized a repo!

Continuing use

From now on, whenever you make changes to the files/code in the directory of your repo, just add the files again and commit with an appropriate message that is concise and states what has been changed in this commit.

$ git add .
$ git commit -m "Add new section on committing to git-tutorial.txt"

Helpful sources

Official git tutorial on git website