Search code examples
gitgit-commitgit-add

Why add and commit in git?


I'm new with and I ask me why I have to use 'git add' and 'git commit' to commit a file into my repository.


With all IDEs I tried it is just one click to commit a file. This means the IDE combines 'add' and 'commit', right?!

And so I can't find any reason why it made sense to program both commands.


Solution

  • Changes can spread over multiple files, and you bundle all those changes in a single commit, with a clear title of what you've done.

    For example in web development when you're done creating a new page you've probably changed multiple files. Your commit message could be: Add index page wich contains files:

    • index.html

    • script.js

    • ...

    After pushing this to remote the next person that pulls will get a somewhat finished index page, instead of just a single file.