Generally whenever i want to push in the changes to remote Git i follow thee steps:
git stash
git pull
git stash pop
//Resolve conflicts if any
git push
However i have also seen my teammates doing the following:
git pull --rebase
//Resolve conflicts if any
git push
I just want to know is there anything beneficial over one another. Or even if there is any other approach that is good.
It depends on your needs:
rebaseproduces a linear history whilepullcould lead to merge commits. I’s described in detail on that answer: https://stackoverflow.com/a/804178/520162And your approach is only equivalent to
git pull --rebaseas long as you didn’t commit anything since your last pull.Side Note:
If you’re using Git really that way, you’re using it wrong. It’s not like SVN where you have to ensure that your repo is in sync with an upstream repo before you could commit.
The usual Git workflow is:
fetchupstreamcommits)fetchupstream againmergeorrebaseyour changes into upstreampushto upstreamMaybe you should browse a bit through Git for beginners: The definitive practical guide