02. Initializing and Cloning a Git Repository

We must first learn how to initialize a Git repository before learning any Git subcommands.

Initializing your first Git directory

Let's create one a project called fun-project, and move into it by typing the following:

$ mkdir fun-project
$ cd fun-project

Once we're in our directory, we can initialize Git with the init subcommand.

$ git init
Initialized empty Git repository in /Users/johndoe/test/fun-project/.git/

Great! You just created your first Git repository! By running the init subcommand, you have created a hidden folder in the current directory called .git. This folder, along with any of its contents, should not be edited or removed.

Cloning an Existing Repository

If you're more interested in someone else's work and want to look at their source code, or just want to download a cool application off of Github, we can use the clone subcommand.

Here, we're obtaining source code from Heng Li, a renowned bioinformaticist who has contributed heavily on Next Generation Sequence data analysis. We'll pull in wgsim, an artificial reads generator. Although this project has been retired and is no longer maintained, it's good enough for demonstration purposes. Simply copy the URL on the side (click the clipboard button) and paste it after the clone subcommand.

Pulling in wgsim from Github
You can find thousands of projects and download their source code off of Github!
$ git clone https://github.com/lh3/wgsim
Cloning into 'wgsim'... remote: Counting objects: 43, done. remote: Total 43 (delta 0), reused 0 (delta 0), pack-reused 43 Unpacking objects: 100% (43/43), done. Checking connectivity... done.

This command will download all the project contents into your local hard drive. You may now go ahead and tweak the files or use the program without affecting the main repository online.

Checking the status

One of the most frequent and informative subcommands you'll use is status. With this, you can check which files are in the staging area (ready to be placed in the next commit), and what is and is not being tracked.

$ git status
On branch master Initial commit nothing to commit (create/copy files and use "git add" to track)

We can see that we're on the branch master, which is the default git branch. We also see that we have nothing to commit (yet). Considering we have not created any files yet, this is true and expected. Let's now create some files and add it to our repository!

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Learn to be a Pythonista!

Programming for Beginners

Learn to be a Pythonista! Try Python

This book doesn't make any assumptions about your background or knowledge of Python or computer programming. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(124+ reviews)

More Python resources