2

I started using git when I was studying for small projects and then the workflow was git add file when having made a new file and then git commit -m ... for subsequent changes.

Now I'm in a new professional larger project where we use git flow. we didn't have any actual problems with git but I wonder why I must make git add now every time I make changes. Is it because I always make a new branch for just myself when we use git flow and therefore I must add the files to an initially empty branch?

Can you please let me know how I can get more skilled at using git flow ?

2
  • 2
    You have to git add even with plain git to stage files for commit. It's just that if you explicitly list what you want to commit with git commit, it does staging for you. But if you don't specify list of files to commit, then git commit only commits files you staged with git add.
    – hyde
    May 7, 2015 at 7:03
  • 3
    You don't want any implicit git activity on every save in your editor; you want to git only on meaningful steps May 7, 2015 at 7:13

1 Answer 1

8

Often you have files which appear in your project directory which you don't want to have in your git repository. For example files the software reads and writes in its own directory as part of its operation. That's why git doesn't blindly index everything in the project directory but instead asks you to add files manually. Also, any binary files should usually not be added to git because it can not handle them well.

Also, sometimes you make multiple changes which are actually separate issues. In that case you often want to break it down into two separate commits by first adding the changes to one file, committing it, and then adding the others.

When this problem does not apply to you in your case, you can use git add --all to add all files in the directory. You can even use git commit --all to add and commit all files in your working tree with a single command.

2
  • Isn't that the whole purpose of .gitignore? Why add an additional step that requires I keep track of all the files that I'm changing? The more I look into and attempt to learn this piece of software the more ridiculously convoluted it seems. Aug 27, 2019 at 22:56
  • I just checked if I was wrong all those years, but no, git commit --all doesn't add files that were not added via git add before. It only commits all the (already tracked) files that were modified since last commit and already added.
    – chriscatfr
    Dec 30, 2019 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.