Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change branch and pull from another branch?

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading