I can make changes to a file in VS Code and Git will track those changes (even though they are not immediately staged, I can stage them easily when committing by using git commit -a). Same thing goes for files that I delete. However, new files that I create are a different story; Git does not track them and thus they are not staged when I use git commit -a. I have used IDEs before that give the option to automatically run git add on a file when I create it. I would like to have the same option in VS Code.
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
@JordanLongstaff Do new files appear in the Git view at all? They should appear as untracked. And if you type a commit message and commit, they will be automatically added and tracked.
Are you expecting me to use VS Code for my commits? Because I'm not. I'm using a terminal. When I do git status, the new files I created are listed as untracked. When I do git commit -a, they are not added to the commit and remain untracked.
Got it. If you're not using VS Code to commit the files, then it should definitely not automatically add them to the repo either. This doesn't seem like an issue with VS Code at all, right? Repro steps:
git status shows themgit commit -a doesn't commit themVS Code seems irrelevant to this. I suggest you file an issue and/or ask in StackOverflow for a solution to your problem.
This is a feature request. I want VS Code to automatically run git add on any new file I create.
Please reopen this.
@JordanLongstaff I see why you'd think this would be useful for your use case. But here's why it's a bad idea:
When you run git add it stages a file with the contents it had in that moment in time. If you continue typing in the file, there are now two versions of the file, as far as Git is concerned: the index version and the working tree version. If you were to commit then, only the initial contents would be in the commit and the file would stay "dirty". So... there isn't a solution as to the problem: when exactly should VS Code run git add on a new file.
That's not a problem for me. If I make a new file with Android Studio (which runs git add on new files upon creation) and then make changes to it, git status shows two changes to the same file, one staged ("new file") and one not ("modified"). But then if I run git commit -a, both changes will get committed.
This applies to other SCM providers as well, for mercurial we would love to be able to detect when files are added, deleted, or renamed via some VS Code API. The workflow in hg is to add once and future changes are included in that added file, so automatically adding is very useful. Perhaps more importantly for this use case, we would love to be able to detect renamed files. There's no git-like staging in hg and being able to run an hg command in response would let us keep blame through renames and remove the need to add the new file and mark the old as deleted after renaming.
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
This feature will also help working with large mono-repos. When a Git repo contains a lot of files (a few hundred thousand or more), git status becomes slow. Running git status -uno runs much faster at the cost of not displaying unstaged files. If VSCode would add newly created files automatically to Git, they would show up when running git status -uno.
Most helpful comment
:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!