Lucas Lima
Lucas Lima

Reputation: 902

How to stash unchanged files on git?

So, I have some committed files in branch A, but I feel like they really don't belong there. I want to move them, as they are, to another branch B - but I don't want to bring the entire branch A history to B; I just want the files.

Then, I'm looking for a way to stash those files, and then pop this stash on a brand new branch B. I've done this in the past in a pretty trashy way - that is, I literally modified every file adding a new line at their beginning, so they could be stashed. Obviously, this solution is nowhere near smart. Is there any way to stash them?

(other solutions to this task are most welcome as well, by the way)

EDIT: I realize this question is badly written. I should have asked "how to move files between branches", because that is my real goal. Sorry for falling to the XY problem. Anyway, for that question, there is already a great answer - check it out. I'm keeping the question in order to help others who may phrase their problems the same way I did.

Upvotes: 1

Views: 285

Answers (1)

Priyesh Patel
Priyesh Patel

Reputation: 186

  1. You could simply checkout a new branch
  2. then commit your change into your new branch
  3. then checkout the original branch you were on
  4. pull the changes from origin
  5. then simply cherry-pick the commit from #2 above

Upvotes: 1

Related Questions