Git is a distributed version control system and is one of the most used version control systems that is used today.
The major difference between Git and any other VCS is that Git takes a picture of what all your files look like at that moment and stores a reference to that snapshot. On the other hand, other systems tend to store information as a list of file-based changes.
To install Git, you should visit one of the following links depending on your operating system.
After successfully downloading Git, within your terminal you should be able to check the version of Git being used by running the following command:
To start with, it is recommended to set some global configuration settings. For example, to set your username and email address, run the following commands:
git config --global user.name "John Doe" git config --global user.email firstname.lastname@example.org
Note the –global option passed in. This means that you only need to set the values once. If you want to override this with a different name or e-mail address for specific projects, you can run the command without the –global option when you’re in that project.
You may want to set a default editor, for when Git requires you to type in a message. Usually Git will use your system’s default editor, which is usually Vim, however you can set Git to use another editor, such as Emacs by running the following:
git config --global core.editor emacs
To view a list of the Git global configuration, you can run the following:
git config --list
If you’re wanting to track an existing project in Git, head to the project’s directory. To initialise a new Git repository, you can run the following command:
This creates a new subdirectory named .git that contains all of your necessary repository files – a Git repository skeleton.
If you want to get a copy of an existing Git repository – for example, a project you’d like to contribute to – the command you need is git clone [url]. For example:
git clone https://github.com/libgit2/libgit2
That creates a directory named “libgit2”, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version.
If you want to clone the repository into a directory named something other than “libgit2”, you can specify the directory name as the next option on the command line:
git clone https://github.com/libgit2/libgit2 someotherdir
Running through this setup ensures that you’ll be ready to work with your repository.
You should now to ready to contribute to your local repository. To find out how to do so, check out the how to add, commit and push with Git article.