02 CreateRepo
A# Create a Repository
Let's work on creating our first git repository.
All shell commands will be prefixed with >
All comments, text not meant to be parsed by the computer,
is prefixed with #
.
Create a git repository#
First create a directory for our project and cd
into the directory
> mkdir -v nyc-311
> cd nyc-311
-v
flag produces verbose output so you can see what happened after the invocation of the command.
Now lets initialize the git repository. All git commands start with git <verb>
. To initialize the git repo
for our project we invoke the command
> git init
ls -a
> ls -a
. .. .git/
-a
flag tells the ls
command to include hidden directories when displaying files. We can see that there
is now a .git
directory. Unless you really know what you are doing DO NOT EVER modify anything in this
directory. If you delete this directory, the entire history of your project will be gone.
Make our first commit!!#
All good projects should have a README.md to describe the project. So let's start with that. Fire up
you favorite text editor and name a file README.md
.
Add something like this in your README:
# Exploring 311 Calls in NYC
## Description
This repo is for an analysis of 311 calls in NYC using Python 3.4
#
are part of markdown
syntax for designating headings.
Now let's look at the status of our repo using git status
:
> git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
untracked
. What this means is that git
knows that this file has been added but it is currently "untracked" by git. Like the command said let's use git add
to
track changes in the the file by invoking the command git add README.md
.
> git add README.md
git status
again.
> git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
> git commit
-
First line is a one line summary of the commit that is in title case and less then 80 characters, written in the imperative voice.
-
Second line should be blank.
-
Third and subsequent lines should be more details of the commit.
Anyone can look at a commit and examine what was changed. The commit message is where you provide a context of what and why you did what you did in the project.
A good rule of thumb is If applied this commit will,
My commit message is the following:
Checking in README file
* Added short description of the project
* Added python3 as a dependency
### Using Nano as a text editor
If you are using nano, to save your text use Ctrl-O, write a filename and to exit use Ctrl-X.
Now that we have made our first commit we can examine our log!
> git log
* commit aaf89fd77e9b43d99fe32823843a7519b2108c90
Author: Clark Kent <clark.kent@dailyplanet.com>
Date: Sat Nov 05 13:45:11 2016 -0600
Checking in README file
* Added short description of the project
* Added python3 as a dependency
To just get titles of commit messages you can use the following command
> git log --oneline
> git log --oneline --graph --all --decorate
Some helpful commands#
Removing files via git allows them to be recovered.
git rm FILENAME
git rm -r DIRECTORY
git mv OLD NEW
git rm
and git mv
will stage the changes that will ulimately
need to be commited.
That is it we have our first commit and repo! Next we are going to write some code!