Best practice to Remote Push in Git
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:
- GitHub Api check number of approvals on protected branch
- ways to publish pages in github using markdown without having to install jekyll or other tools
- Not able to checkout branch even after removing worktree and running worktree prune
- How do I merge an existing git repository into an empty one and preserve the history?
- Changing commit metadata on all commits
- Why does git create merge commits? And how to remove these?
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.
2 Solutions collect form web for “Best practice to Remote Push in Git”
It depends on your needs:
rebase produces a linear history while
pull could lead to merge commits. I’s described in detail on that answer: https://stackoverflow.com/a/804178/520162
And your approach is only equivalent to
git pull --rebase as long as you didn’t commit anything since your last pull.
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:
- tell your story (i.e. do a bug fix, an improvement, whatever; do some
- once you’re done it’s time to
rebaseyour changes into upstream
Maybe you should browse a bit through Git for beginners: The definitive practical guide
You want to avoid rebases. This applies mainly to permanent branches. Topic branches may use either.
Another thing to add is
git config --global push.default current
This ensures you push only the current branch when you issue the push command.