When do I need to do “git pull”, before or after “git add, git commit”?

前端 未结 6 938
忘了有多久
忘了有多久 2020-12-22 16:14

What is the right way?

git add foo.js
git commit foo.js -m \"commit\"
git pull
git push

Or

git pull
git add foo.js
git comm         


        
6条回答
  •  情书的邮戳
    2020-12-22 16:46

    I'd suggest pulling from the remote branch as often as possible in order to minimise large merges and possible conflicts.

    Having said that, I would go with the first option:

    git add foo.js
    git commit foo.js -m "commit"
    git pull
    git push
    

    Commit your changes before pulling so that your commits are merged with the remote changes during the pull. This may result in conflicts which you can begin to deal with knowing that your code is already committed should anything go wrong and you have to abort the merge for whatever reason.

    I'm sure someone will disagree with me though, I don't think there's any correct way to do this merge flow, only what works best for people.

提交回复
热议问题