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

git

Solution

I think that the best way to do this is:

Stash your local changes:

git stash

Update the branch to the latest code

git pull

Merge your local changes into the latest code:

git stash apply

Add, commit and push your changes

git add
git commit
git push

In my experience this is the path to least resistance with Git (on the command line anyway).

Problem

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 commit foo.js -m "commit" git push ``` Or ``` git add foo.js git pull git commit foo.js -m "commit" git push ``` UPD: I forgot to mention that in this case I use `git add` to stage a tracked and modified file. Not to include a brand new file to repository. Does this changes an order of commands?

Original source

Related problems