Search code examples
gitgithubgist

How to upload one file repository to Gist, preserving history?


I have a Git repository on my computer with a single file coins.py

How can I get that as a Gist on Github, preserving history?


Solution

  • This is actually quite simple. You can move your existing history into a Gist repo like you would move it into any other:

    1. Create a Gist (simply enter a few random characters, so it gets created; enter a title if you want)
    2. Copy the URL of the newly created Gist (it has the form https://gist.github.com/<LONG-HEXNUMBER>.git (if you prefer using SSH URLs, you can use git@gist.github.com:<THAT-SAME-HEXNUMBER>.git instead)
    3. In your existing local repo, do git remote add origin <URL>, where origin is an unused local name for the remote
    4. Push your changes: Assuming you have a local master branch, you will want to overwrite the remote one with git push -f origin master
    5. Push any other branches or tags you want on the remote as usual.