I have this question just wanna someone to explain it in my context.
I have my main branch - call it dev i have created a branch from dev - call it myTest i have created another branch from myTest - call it myTest/myTestPart1
Normally when someone push something to dev i do git checkout dev - i pull everything from here - i do git pull
then i do git checkout myTest and rebase it from dev - i do git rebase dev and then git push -f
then i go to myTest/myTestPart1 and do git rebase myTest and then i do git push -f
Today another dev was working with me and he said i need to do git fetch origin and go to the remote version of dev and do rebase the current into selected
What is the difference between what i was doing and what he said to me?
Thank you
CodePudding user response:
One difference is that he uses sentences that start with a capital letter and end with a period, and you don't. :)
What he's saying is that you're wasting a lot of effort and time and Internet bandwidth. You don't need to checkout dev
and pull it in order to rebase onto it. And since you don't need to checkout dev
, you don't need to swith to myTest
— because you are already on it.
The way to rebase myTest
onto latest version of dev
is to stay on mytest
and say
git fetch origin
git rebase origin/dev
You have to admit that's a lot shorter than what you're doing.
CodePudding user response:
The fetch command is mandatory if you want to be sure you are working with updated branches. Without this, ... you rebase into a local history of dev that can be a little bit different from yours.
From atlassian documentation:
In review, git fetch is a primary command used to download contents from a remote repository. git fetch is used in conjunction with git remote , git branch , git checkout , and git reset to update a local repository to the state of a remote.
If you rebase into your local (and not updated) dev you could simply lost some informations and some colleagues updates.