Git

Git is a popular distributed version control system created by Linux kernel creator, Linus Torvalds. This page focuses on using Git for both solo and group projects. Currently, this page is a work in progress.

Getting started

Installing Git

Debian-based Linux distros

If your using a Debian based Linux distro (Debian, Ubuntu, Mint, elementaryOS, etc), install Git through apt-get

[sudo] apt-get install git-core

RPM based Linux distros

If your using a RPM based Linux distro (Red Hat, Fedora, CentOS, etc) install Git through yum

yum -y install git-core

Windows

For Windows, download the installation exe from the Git website and install it.

Creating a new user

Before you can create and manage repositories, you need to set a username and email address.

git config --global user.name "username"
git config --global user.email useremail@example.com

-

Creating a repository

Open the directory where your source code is located in a terminal (or command prompt if your a Windows user) and type the following:

git init

This will turn the directory into a Git repository.
-

Committing changes to a repository

Before you make a commit, your must first add all of the files to the staging area by typing the following command for each file you want to add:

git add <filename>

Now to commit these changes you must type the following command:
git commit -m "<commit text>"

If you don't put a -m argument, Git will open up a text editor which will allow you to write a multi-line commit.
-

Viewing changes

To viethe history of changes to a repository, type the following command:

git log

This will produce the following result:
commit <commit id>
Author: <user name> <user email>
Date: Sun Mar 11 08:05:26 2018 +0530

<commit text>

To view the changes of a certain commit, type this instead:

git show <commit id>

Online repositories

With Git (and any other version control system) you can push your commits to an online repository.

Adding a remote repository

To add a remote repository where you can push changes to, type in the following command:

git remote add <name of remote repository> <url of repository>

This allows you to push commits without entering the repositories URL everytime.

Pushing to remote repository

To push changes to a remote repository, type in the following command:

git push <name of remote repository> master --force

A log in prompt will usually appear.

External Links

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License