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!

Learn how teams work in Agile

Scrum: A Brief and Agile Introduction

Learn how teams work in Agile Try Productivity Tools

If you're looking to learn the elements of Agile development and Scrum, this is the book for you. This book has been reviewed by many, and sought after as a must-read for anyone who works in agile. The book is brief, with no anecdotes nor reiterations. Just pure content to help you graph what Scrum is in no time.

$ Check price
9.959.95Amazon 4.5 logo(568+ reviews)

More Productivity Tools resources

Learn to be a Pythonista!

Programming Python

Learn to be a Pythonista! Try Python

Programming Python shows in-depth tutorials on the language's number of application domains including: system administration, GUIs, the Web, networking, front-end scripting layers, and more. This book focuses on commonly used tools and libraries to give you a comprehensive understanding of Python’s many roles in practical, real-world programming.

$ Check price
64.9964.99Amazon 4 logo(56+ reviews)

More Python resources