55

I cannot understand this.

I have created a gist. Then I run

$ mkdir mygist
$ cd mygist
$ git init
$ git pull git@gist.github.com:869085.git

Then I add files, change files and try to commit.

$ git add .
$ git commit -a -m "Better comments"

Then I do not know how to send it back to github and commit this git.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sergey
  • 561
  • 1
  • 5
  • 3
  • 1
    I just wanted to a comment to anyone trying to do this: **You cannot add folders to a gist** (Or least I couldn't when I tried). I couldn't push if I tried to add a folder to the gist which lead me to believe the answers below didn't work. But they do, just don't commit folders. – Rico Kahler Dec 08 '17 at 11:09
  • 3
    In case anyone comes across this whilst trying to push over https, check if you have 2FA enabled, then you need to generate a token to push: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ – sinewave Sep 25 '18 at 13:35

3 Answers3

87

It's probably easiest if you just start by cloning the gist, so that origin (a "remote" that refers to the original repository) is set up for you. Then you can just do git push origin master. For example:

git clone git@gist.github.com:869085.git mygist
cd mygist
# Make your changes...
git add .
git commit -m "Better comments"
git push origin master

However, if you don't want to redo your changes, you can do:

cd mygist
git remote add origin git@gist.github.com:869085.git
git fetch origin
# Push your changes, also setting the upstream for master:
git push -u origin master

Strictly speaking, the git fetch origin and -u argument to git push origin master are optional, but they will helpfully associate the upstream branch master in origin with your local branch master.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Thai is what I was trying to do but when I do $ git push origin master I get Enter passphrase for key '/c/Users/user/.ssh/id_rsa': ERROR: Permission to 869085.git denied to MightyTechnologies/Mighty-Solution-CMS. fatal: The remote end hung up unexpectedly – Sergey Mar 16 '11 at 12:40
  • 1
    @Sergey: this is a guess, but it might be that you haven't added the public key from `/c/Users/user/.ssh/id_rsa.pub` to the SSH public keys of the MightyTechnologies account? Otherwise, perhaps some of [the advice here](http://help.github.com/troubleshooting-ssh/) might help? – Mark Longair Mar 16 '11 at 12:55
  • 1
    @JJD: your edit to this answer switched to using `git branch -u`, which was only introduced in git very recently (v1.8.0) so I've changed the answer to use `git push -u origin master`, which saves a command as well. – Mark Longair Apr 09 '13 at 07:51
  • 4
    The important thing is the git address is of the form `git@...` not `http:...` as the obvious 'clone' field on the gist pages uses. – tacaswell Apr 29 '13 at 18:39
12

Since you did not use git clone you have no remote set up. While Mark Longair's solution is the best, an alternative would be:

git push git@gist.github.com:869085.git
igorw
  • 27,759
  • 5
  • 78
  • 90
  • 1
    Thai is what I was trying to do but when I do `$ git push origin master` I get `Enter passphrase for key '/c/Users/user/.ssh/id_rsa': ERROR: Permission to 869085.git denied to MightyTechnologies/Mighty-Solution-CMS. fatal: The remote end hung up unexpectedly` – Sergey Mar 16 '11 at 12:42
1

You just need to use the git push command to send that to github.

Artusamak
  • 2,470
  • 19
  • 19
  • Thai is what I was trying to do but when I do $ git push origin master I get Enter passphrase for key '/c/Users/user/.ssh/id_rsa': ERROR: Permission to 869085.git denied to MightyTechnologies/Mighty-Solution-CMS. fatal: The remote end hung up unexpectedly – Sergey Mar 16 '11 at 12:42
  • Well the message is saying that you are not allowed to write on that git repository. Are you sure that your public specified on github is the right one? – Artusamak Mar 16 '11 at 13:53