Skip to content

Getting Started With Git

Abinav Seelan edited this page Aug 31, 2016 · 6 revisions

Installation

Linux

If you are on Ubuntu, you can just run the following commands to get the git package from the Ubuntu Package Repository

 $ sudo apt-get update
 $ sudo apt-get install git

Windows & OSX

Visit git-scm. Download. Install.

==============

To verify if git has installed correctly

 $ git --version

This should display the git version.

Cool. Now that we have git on our systems, let's dive into some simple commands to get started!

Your First Commit

Ok. Let's talk about commits for a second. Git works on the concept of snapshots. If the history of file changes is a video then a snapshot is a screenshot taken anywhere from that video. Committing is the act of creating this snapshot. That's it! =)

Setting things up

To start things off, let's create a folder to hold our files, shall we?

 $ cd ~
 $ mkdir project_folder
 $ cd project_folder

Executing that will create a folder called project_folder in our home directory and move us into that folder.

Initialising a Git Repository

A repository is a place that holds all those snapshots we create of our files. To initialise this folder to be a repository we run the following

 $ git init

Once you run that, you'll notice that the folder now contains a .git folder. We won't go into a lot of detail on what it contains, but just think of it as housing all those snapshots in it. =)

And that's that...your folder is now a Git Repository. Woohoo!

Adding your first file

Let's create a file in your folder now and add some stuff to it.

 $ touch file1.txt
 $ cat >> file1.txt
   Hello World

This creates a file called file1.txt in your project directory and adds the line Hello World to it.

Now let's see what Git is seeing of our project folder.

 $ git status
 

Clone this wiki locally