Creating git repository for the Python exercises

I feel so happy after creating my first repository on github and successfully adding all the files to it from my local machine!
It took me a lot of time and effort, and there were actually a few times when I thought that I wouldn’t be able to do it. It took me hours, and that is not how much it should have taken to just create a new repository.

I had earlier tried to create a repository using SSH clone and I wasn’t successful. Even this repository I have created is a HTTPS clone. I am yet to master a SSH clone repository. I get lost in the process after adding the SSH keys.

So here I’d like to document the whole procedure I used to create the repository (using HTTPS clone) and the problems I faced mid-way :-

First I went on my github profile and simply created a new repository with the name- Learn Python the Hard Way. This part is too easy and requires no real explanation.
Then I opened my terminal and followed the following procedure:-

1. Initialized the local repository (the directory where I hold all the python exercises) as a git repository.
jigsaw:Python$ git init

Initialized empty Git repository in /home/jigsaw/Python/.git/

2. Added the files from in the new local repository. This stages them for a commit to my git repository.
jigsaw:Python$ git add .

Note: At the end, I’ll also mention the difference between add . and add -A/–all

3. Checked  the status of the files staged for a commit.
jigsaw:Python$  git status

On branch master

Initial commit

Changes to be committed:
  (use “git rm –cached …” to unstage)

new file:   Python File Modes
new file:   Python Files I_O.pdf
new file:   Untitled Document
new file:
new file:
new file:
new file:
and so on..

4. Committed the files that I have staged to my git repository.
jigsaw:Python$ git commit -m “Required message”

[master (root-commit) e0954d9] First commit; Half way through Learn Python the Hard Way

 51 files changed, 3488 insertions(+)
and so on..

5. Next I copied the HTTPS clone URL from the lower right hand corner of my repository on github and added it to the command as follows.

jigsaw:Python$ git remote add origin

From my understanding, here we mean to create a remote (called origin )on our machine that links us to the repo on git through the given URL. I could be wrong.
6. The last step was simple. I just had to push the changes from my local repo ( on my system) to github, using :
jigsaw:Python$ git push origin master 
‘master’ to my git repository.
Just had to type my username and password here and I was done!

Username for ‘’: jigsaw2212

Password for ‘’: 

But I encountered an error message, which said :-

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to ‘’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

I was confused! I looked around, banged my head on the wall a few times and finally understood that what this error message was trying to tell me is that my local repo was not up-to-date with my master on github. This happened because I had added a file upon creation of my repository on github, which made it out of sync with my local repo.

Hence, I first had to pull changes from the git repo to my local machine before pushing my whole project on to github.

jigsaw:Python$ git pull
jigsaw:Python$ git push origin master

And through this I was finally able to push all the scripts I had written in the exercises on to a new repository on github.
Link to repo-

After that, I also created a branch for my project ( so that the master remains clean), using :-
jigsaw:Python$ git checkout -b LPTHW_Next_part
Means, create a new branch and move to it.

I can view the existing branches and the current branch I’m on using:-
jigsaw:Python$ git branch

* LPTHW_Next_part


Next time, I’ll try create using the SSH clone, so that I don’t have to log in again and again when I’m pushing files into it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s