4

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.

Community
  • 1
  • 1
pabo
  • 625
  • 3
  • 14

2 Answers2

3

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.

IQAndreas
  • 8,060
  • 8
  • 39
  • 74
  • I'm definitely open to the idea of solving my core problem with something like this. But I also saw this as an opportunity to learn something new about git. Either way, thanks for the suggestion; it may be what I end up doing in the long run. – pabo Sep 05 '14 at 04:30
2

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
IQAndreas
  • 8,060
  • 8
  • 39
  • 74
  • Thanks for the response. Two questions: 1) are remotes specific to branches? I assume not. So I could mistakenly `push origin master` while I was in the minimal branch, and vice versa? 2) what is the purpose of `--no-ff` in the git merge you proposed? – pabo Sep 05 '14 at 00:23
  • @pabo 1) No, remotes are specific to repositories, **however**, that's why I added the `-u` (or `--set-upstream`) flag in the first block of code. The upstream branch and repository **is** specific to branches. Then when you run `git push` it automatically pushes to the branch you set as upstream, so you don't mistakenly push to a different branch or repo. – IQAndreas Sep 05 '14 at 00:26
  • Furthermore, should the push from the minimal branch look like `git push -u gist minimal` instead of `git push -u gist master`? – pabo Sep 05 '14 at 00:28
  • So once I run the push with -u the first time, I can just run `git push` with no further arguments and it'll go to the correct remote based on the branch I have checked out? – pabo Sep 05 '14 at 00:29
  • @pabo It should be `git push -u gist minimal` since the command looks like this: `git push -u `. Although your branch is named `minimal` in your repo, I believe gists are stored in the `master` branch remotely. – IQAndreas Sep 05 '14 at 00:32
  • @pabo As for the other question, _Correct!_ If you set the upstream git "remembers" where you want to push changes to that branch by default, no further arguments needed. – IQAndreas Sep 05 '14 at 00:33
  • @oabo 2) `--no-ff` isn't strictly necessary, in this case it just makes your git history a little nicer as instead of "globbing together" the `minimal` and `master`. There is [a diagram on this page](http://ariya.ofilabs.com/2013/09/fast-forward-git-merge.html) that shows the difference, but it may be easier if I create a test repo and show you the difference in the history view. – IQAndreas Sep 05 '14 at 00:36