Question:
What is the right way?
1 2 3 4 5 |
git add foo.js git commit foo.js -m "commit" git pull git push |
Or
1 2 3 4 5 |
git pull git add foo.js git commit foo.js -m "commit" git push |
Or
1 2 3 4 5 |
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?
Answer:
I think that the best way to do this is:
Stash your local changes:
1 2 |
git stash |
Update the branch to the latest code
1 2 |
git pull |
Merge your local changes into the latest code:
1 2 |
git stash apply |
Add, commit and push your changes
1 2 3 4 |
git add git commit git push |
In my experience this is the path to least resistance with Git (on the command line anyway).