How to clone gist

Gist is one of the most efficient way to share code snippets, single files and full applications with other people. However one disadvantage of gist is that you can’t share directories, but this is not a major issue considering gist is primarily used to share code snippets.

If you want to make local changes to a gist and push them up to the web, you can clone a gist, make changes and then make commits. It is exactly same process as you would with any Git repository.

Let us look at how to clone gist repository using https

Go to gist repository and get https link. Please find below image to see howto get the https link.

Using following command to clone repository

$ git clone
Cloning into '820c117b75d52514b2e58008be07a6eb'...
remote: Enumerating objects: 44, done.
remote: Total 44 (delta 0), reused 0 (delta 0), pack-reused 44
Unpacking objects: 100% (44/44), done.
Checking connectivity... done.

That is it. You are done. You can cd into the folder and check the files.

How to publish code to gist repo along with github repo

Previously I was keeping code in the same post and I was using code formatting add-ons but then I realised this is very inefficient. While searching for best way to add code to post, I discovered Github gist. It is very useful to add code snippets to blog.

However, while using gist, I stumble across a problem. I had to maintain same code at two places, one on github repository and second on gist. Many times, I was updating my old code, now this lead to problem of updating same two at two places. Github repository was getting updated by git push however, I had to manually updated gist. I did not spend much time to find solution as it was not taking much time, nonetheless this was awkward and I made a mental note to find a workaround sometime later.

Today I did a bit research and found couple of methods. Following is the most efficient method that I found.

Step#1 Create your Github repo as usual.

Please check the post Publish local repository to Github using https for creating local repository for your Github repository

Step#2 Create a Gist repository and add this as another remote

Gist are nothing but repository only. Create gist repository from

Gist name will be first file name that you will create. Keep the first file name same as that of Github repo whose copy you want to maintain as Gist.

Now we need to add this repository as remote with name gistrepo on your local repository. I chose to add gistrepo using https as this is easiest, you can get this link as below

Use following command to add remote gistrepo

git remote add gistrepo

You can check remote by using following command

$ git remote -v
gistrepo (fetch)
gistrepo (push)
origin (fetch)
origin (push)

Step#3 Push changes to gistrepo after pushing changes to origin i.e. github repo

First push changes to your Github repository.

$ git add .
$ git commit -m "test changes"
$ git push -u origin master
Username for '': conquistadorjd
Password for '': 
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.49 KiB | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
c813187..5c0472f master -> master
Branch master set up to track remote branch master from origin.

Once done, push these changes to your gistrepo repository. While pushing the changes, please make sure you use -f instead of -u.

$ git push -f gistrepo master
Username for '': conquistadorjd
Password for '': 
Counting objects: 12, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (12/12), 2.59 KiB | 0 bytes/s, done.
Total 12 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
+ cecff3f...5c0472f master -> master (forced update)

Now go and check your gist and Github, both will be in sync and wherever you have used the code, it will be get updated.

Publish local repository to Github using https

Follow below steps to push local repository to github


Create new empty repository on github
Please make sure you do not select Initialize this repository with a README checkbox


If you want to create new local repository

echo "# any comment you want to add" >>
git init
git add .
#git add  # this works as well
git commit -m "first commit"
git remote add origin
git push -u origin master 

Last step will ask you for  Github userid and password.
It will take some time to upload your changes to github depending on size of your changes. Once this is completed, go yo github and verify.

Git Quick Reference

Git is the most useful tool for developers but if someone does not use it for a while, it all seems confusing. Git is tricky. Here are some of the most commonly used command.

Installing git

$sudo apt-get install git

Create new git repository

$git init

Create git repository on server

$git init --bare

Please note the difference : A bare repository is a git repository without a working copy, therefore the content of .git is top-level for that directory.

Use a non-bare repository to work locally and a bare repository as a central server/hub For example, when you create a repository on, it is created as a bare repository.

To conclude, the repository on the server side is going to get commits via pull and push, and not by you editing files and then committing them in the server machine, therefore it is a bare repository.

You can push your changes from local to remote by using following command

$git remote add live ssh://

once this is added you can check all remotes using following command

$ git remote -v
live ssh:// (fetch)
live ssh:// (push)

Deploying the changes.

Once your changes are ready, you can deploy it using following commands

git add .  
git commit -m "commit comment"  
git push live master  

Copy remote repository to your local folder.

$git clone ssh://  

To get list of files changed in directory

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: MySQL/

Untracked files:
(use "git add <file>..." to include in what will be committed)

MS Excels/

no changes added to commit (use "git add" and/or "git commit -a")

Get commit history

$git log