What is the difference between git add, push and commit?
Just a little confused coming from SVN, where “update” will ‘add’ stuff, and commit does a “push” and will ‘add’ as well
There are all different functions within git. Hoping for some explanation from your experience.
git addadds your modified files to the queue to be committed later. Files are not committedgit commitcommits the files that have been added and creates a new revision with a log… If you do not add any files, git will not commit anything. You can combine both actions withgit commit -agit pushpushes your changes to the remote repository.This figure from this git cheat sheet gives a good idea of the work flow
git addisn’t on the figure because the suggested way to commit is the combinedgit commit -a, but you can mentally add agit addto the change block to understand the flow.Lastly, the reason why
pushis a separate command is because ofgit‘s philosophy.gitis a distributed versioning system, and your local working directory is your repository! All changes you commit are instantly reflected and recorded.pushis only used to update the remote repo (which you might share with others) when you’re done with whatever it is that you’re working on. This is a neat way to work and save changes locally (without network overhead) and update it only when you want to, instead of at every commit. This indirectly results in easier commits/branching etc (why not, right? what does it cost you?) which leads to more save points, without messing with the repository.