4

I want to stash work in progress, but I also want what I've stashed to be backed up on GitHub. Previously I've normally committed with a comment saying "WIP: blah blah blah", but I'd rather commit in completed stages rather than loads of "WIP:" commits which are really just a way to backup my work to the GitHub servers.

Is there a way to have stash to GitHub?

random
  • 9,774
  • 10
  • 66
  • 83
Jimbo
  • 4,352
  • 3
  • 27
  • 44

3 Answers3

12

You can't put the stash on GitHub, but you can (and should) create a branch and commit to that:

git checkout -b temporary
git add -A
git commit -m "storing work in progress"
git push

Then just merge temporary into master (or whatever) when it's ready.

Edit: removed superfluous stash commands.

Jim Stewart
  • 16,964
  • 5
  • 69
  • 89
  • Thanks, makes sense. I'll have to do a bit more learning I think... will that work with GitHub or do I have to create the new branch on GitHub first? – Jimbo Aug 21 '13 at 22:29
  • You can create as many branches as you want, and they'll all get pushed to the repo. GitHub sits on top of standard Git repos, and handles branches automatically. As soon as you push, it'll be visible in the GitHub UI (look for the "branch: master" selector above the file list). Anyone who clones the repo will get all the branches, too. – Jim Stewart Aug 21 '13 at 22:32
  • 1
    Just remove both stash commands from that list and everything still works. The use of stash doesn't make sense here :) – Christoph Aug 22 '13 at 01:23
  • For some reason I thought you couldn't checkout a branch with actively-modified files, but @Christoph is right; you don't need to stash at all in most cases (and not when creating a new branch). If you switch to an existing branch there are scenarios when you might have to stash first, but that's not the scenario Jimbo was asking about. – Jim Stewart Aug 22 '13 at 16:35
0

The stash cannot be saved into remote repository. But what you have to be doing is creating new branch for your work-in-progress work.

Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60
-1

You should be able to push your stash directly:

git push origin stash

See also git log stash.

michas
  • 25,361
  • 15
  • 76
  • 121
  • 1
    This is wrong, you're assuming that `stash` is a branch. What the OP is asking about is the built-in git stash. Run a `git stash --help` for yourself. – Civilian Nov 10 '14 at 20:55
  • `stash` is not a branch but nevertheless a valid ref! – michas Nov 10 '14 at 21:22
  • 1
    Sorry I was slow on following up on this--- Is this a new/old feature? Here's my terminal output. http://collabedit.com/v2gjh It doesn't look like a valid ref. – Civilian Apr 10 '15 at 21:43
  • 1
    Is there any chance you're using tfs wrapped by git? – Civilian Apr 10 '15 at 21:46
  • Stashes is a valid ref but not a valid branch. Git will complain. But a working solution can be found in [this answer](https://stackoverflow.com/a/5248758/3088045) – Kamafeather Feb 10 '19 at 22:23