zwolin
zwolin

Reputation: 994

How to move a single new file to a new branch in git

I have one new staged file A on branch branch_A. There are some changes in other files as well on branch_A.

I want to create a new branch - branch_B and move file A to branch_B without moving changes in other files on branch_A.

Is that possible? If so - how?

Upvotes: 0

Views: 37

Answers (1)

Stefano
Stefano

Reputation: 4031

Start by creating the new brunch

git branch branch_B

Then move the file using git stash. if you want to stash a single file you can do the following:

git add myFileToMove
git stash --keep-index

If you have not made the commit yet, just run git stash. This will save away all of your changes. Switch to branch_B and run git stash pop.

Upvotes: 1

Related Questions