Skip to content

Instantly share code, notes, and snippets.

@jprivet-dev
Last active September 30, 2023 22:16
Show Gist options
  • Save jprivet-dev/6e7e81c3c0497a6292dd760559840fb1 to your computer and use it in GitHub Desktop.
Save jprivet-dev/6e7e81c3c0497a6292dd760559840fb1 to your computer and use it in GitHub Desktop.
Transfer a Gist into a new GitHub repository

Transfer a gist into a new GitHub repository

1) Create an empty repository on GitHub

Create a new repository on GitHub (in my case git-and-bash-aliases).

To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.

2) Clone the gist

$ git clone git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git git-and-bash-aliases
$ cd git-and-bash-aliases

With the git clone command, the folder will be named by default with the gist reference (in this case 09912ca4188a4ba3c610d7f61c200c38).

I prefer to give my folder a more explicit name to make it easier to find my way around my gists.

3) Adjust the remote names (gist & origin)

remote target
origin new GitHub repository
gist original gist repository

Convert origin name to gist

$ git remote -v 
origin	git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git (fetch)
origin	git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git (push)
$ git remote rename origin gist
$ git remote -v 
gist	git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git (fetch)
gist	git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git (push)

Connect the new GitHub repository to origin

$ git remote add origin git@github.com:jprivet-dev/git-and-bash-aliases.git
$ git remote -v 
gist	git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git (fetch)
gist	git@gist.github.com:09912ca4188a4ba3c610d7f61c200c38.git (push)
origin	git@github.com:jprivet-dev/git-and-bash-aliases.git (fetch)
origin	git@github.com:jprivet-dev/git-and-bash-aliases.git (push)

4) Push all on the new GitHub repository

$ git branch -M main
$ git push -u origin main

That's all ¯_(ツ)_/¯

Resources

@nathanbrauer
Copy link

FYI, you can save yourself the trouble and use GitHub's import tool:

  1. Go to your gist, copy the URL for "Clone via HTTPS"
  2. Go to your repositories, click on New then click on the "import a repository" link (or just click here)
  3. Paste the URL, choose a name and click on "Begin Import"

hat tip to @rolfen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment