How to change branch and pull from another branch?
Answer a question
I'm kind of new to Git and I don't feel safe running commands. I'm working on Branch A and I made a lot of changes. I need to work on another branch (Branch B) that doesn't have the files of Branch A. I'm not ready to make a merge of the branches.
Is it the right way if I commit and push to Branch A then fetch --all and checkout to Branch B. Then I pull from Branch B do the required work with the files of Branch B and commit and push in Branch B to later return to Branch A and pull the pushed files I made before?
I read about stash but I'm not sure if in this case it would be useful.
Answers
It's sort of a matter of opinion, but I don't like stashing if I don't have to; if I'm in the middle of unfinished work on Branch A and I'm told to work on Branch B, I do an add-and-commit with a wip commit message (to indicate that this is "work in progress"), and then git fetch; git switch branchB.
No need to say fetch --all. No need to push Branch A (and it's probably a bad idea to do so, since it isn't baked yet). No need to pull because the fetch updated everything.
But if you already had a local Branch B, then after you switch to Branch B you might need to say git merge to update the local branch.
更多推荐


所有评论(0)