Link a gist with a github repository, but push dif

2019-04-13 18:14发布

I created a project as a single file gist. Then I expanded my project to multiple files (by, for instance, adding README and LICENSE files). I set up two remotes on my local git repository now, which I call origin-gist and origin-github. I can push to them and everything is right with the world.

But what I actually want is for the gist to remain just the single file, without the overhead of the added stuff. How can I do that while keeping one local repository that pushes to the two remotes?

As an aside, if I could control the order that the files displayed in gist I would care less. I'm also unwilling to rename my files to induce the desired order with an ASCIIbetical sort.

Any tips?

I found information in this question useful: Transfer gist repo to github, but need some clarification.

标签: git github gist
2条回答
\"骚年 ilove
2楼-- · 2019-04-13 18:59

The easiest solution is probably to keep two separate branches, one with only the script (which I would name minimal) and one with all the extra files in it (master). Then make sure the "upstream" for each branch is set properly:

# In the 'minimal' branch
git remote add gist git@gist.github.com:/1162032.git
git push -u gist master

# In the 'master' branch
git remote add origin git@github.com:octocat/Hello-World.git
git push -u origin master

After that, you just need to make sure that both scripts stay up to date, so any change you make to one branch should be made to the other branch as well.

You can make this easier in one of two ways:

  1. When you make changes, cherry-pick commits from one to the other.
  2. If you merge the master branch into the minimal branch whenever you make changes, it will add those extra files to minimal. But assuming the minimal branch only contains the actual script, you should be able to safely merge from minimal into master without adding those extra files:
# First, make edits to the 'minimal' branch, commit them, then push the changes to 'gist'
# Now, apply those changes to master like this:
git checkout master
git merge --no-ff minimal -m "Update script to latest version"
git push # Push the changes to the GitHub repo
查看更多
Anthone
3楼-- · 2019-04-13 19:05

This answer doesn't directly answer the specific question you asked, but it does solve the problem at hand, and has therefore been added as an answer rather than a comment.

It is worth asking yourself, is there a reason to keep the old gist around and updated?

The easiest solution to this problem, and what I frequently see, is the gist replaced with a README document that says something like:

This gist has been moved to its own repository: http://github.com/OctoCat/HelloWorld

Take this "former gist" as a prime example: https://gist.github.com/weakish/492755

This way people who find the gist online can be directed towards the newest version of the library, and you don't have to worry about keeping both separate locations up to date.

查看更多
登录 后发表回答