Do you use git? Then this is for you...
7 ways in which you can add files to your commit using git add
2 min read
Table of contents
- 1) Add all files
- 2) Add just a specified file
- 3) Add files with a specific extension
- 4) Add all files under a particular directory
- 5) Add all files which are usually ignored via gitignore
- 6) Add all files except deleted files
- 7) Add all files except new files
For anyone who uses git, git add is the most commonly used terminal command to add files. But have you ever wondered if you can add only newly created files or just a specific type of file? Well, you can, and what's more interesting is you can do more than that with git add.
Let's dive right in!!!
1) Add all files
The below line can be used to select all files such as
newly created files
git add .
2) Add just a specified file
Lets assume that you edited multiple files, but you want to add just a specific file to the commit, then use the below command
git add < path-to-file >
//eg: add just the CSS file from the specified path git add apps/project-structure/styles.css
3) Add files with a specific extension
git add *.< file-extension >
//eg: add all files with extension scss git add *.scss
4) Add all files under a particular directory
Using the below command one can add all the files under a particular directory path
git add < directory >
//eg: add all files under the folder project-test git add apps/project-test/
5) Add all files which are usually ignored via gitignore
Using the below command one can add all the files which are generally ignored via gitignore
git add -f
git add --force
6) Add all files except deleted files
Using the below command one can add all the files i.e newly created files and modified files, but this command will ignore the deleted files
git add --ignore-removal
7) Add all files except new files
Using the below command one can add all the files i.e modified files and deleted files, but this command will ignore newly created files
git add -u
git add --update
Follow me on Twitter | LinkedIn for more web development related tips and posts. Feedbacks and suggestions are welcome.
Are you more of a Twitter person? Then check out the short version of this blog in the below thread.
Did you find this article valuable?
Support Kritika Pattalam Bharathkumar by becoming a sponsor. Any amount is appreciated!