Let say I am working in branch-X and made some changes (about 50 files). Rather committing those to branch-X I want to commit those changes to branch-Y. So how to do this without committing in branch-X. Just to add, there are few files which are related to branch-X changes.
Asked
Active
Viewed 755 times
2 Answers
3
Perhaps the easiest approach here would be to just stash your working directory on branch X
, and then apply that stash to branch Y
:
# on branch X
git stash
git checkout Y
git stash apply
Note that you may get merge conflicts when you apply the stash, and you would have to resolve those.
It might also be possible to just checkout branch Y
directly and then make a commit, but I am not sure if this would work out if there are files being added/removed. In that case, stash is probably a safer bet.

Tim Biegeleisen
- 502,043
- 27
- 286
- 360
0
Just
git checkout Y
# (any git adds here)
git commit
Changes in your index or worktree remain there until you commit.
If your work is in files that already differ between the two branches you can
git checkout -m Y
to merge the changes. There may be conflicts you have to resolve, but you'd have to resolve them anyway.

jthill
- 55,082
- 5
- 77
- 137