To add all files & folders on git, use the following command:
git add -A
This command will stage all the changes for the next commit. There are some other similar commands on git that I will discuss later in this post.
Git is one of the most popular version control systems around the globe. It keeps track of the changes to your project. You can learn more about Git, why it is used, why people like it so much, etc in this post.
Troubleshoot — Commands before git add -A (all)
If you see a fatal error such as “command not found” or “not a git repository”, there is a chance that you have not installed & configured Git on your machine. Let’s follow the following steps:
Check if Git is installed on your machine?
You can not just type
git add -A to stage all the files. Before adding all the files, you have to make sure Git is installed on your machine.
To check whether it is installed or not, open your command line or terminal, type the following command, and hit enter:
This command will show you the installed version. But if you see an error like a command not found or any other error, it means that Git is not installed on your machine.
In that case, you have to install Git first. I am using VS Code terminal but you can use Git Bash, Mac Terminal, or whatever you like.
Configure your global username & email
Git also needs to check who is making the changes. So you have to configure your global username & password before you add all files to git.
If you have not configured it yet, see the first-time configuration in the video below:
Initialize a Git repository
Before you add untracked files, you have to initialize a Git repository. Use the
git init command to do that.
Now you’re ready to add all changes or stage the files. That means, after making the above changes, you’re able to use the
git add -A command.
The next command after adding all files to the git will be
git commit -m "a custom message" and from there you can push your local repository to a remote origin such as GitHub.
This is how you can troubleshoot if you find an error while staging all files.
Adding specific files to git
Sometimes you may also need to add a specific file. To add a specific file, use the following command:
git add file_name
git add index.html
You can also add multiple files followed by a space.
git add index.html sass/style.css
In this example, the second file lives in a folder named “sass.” That means you also have to mention the file path while adding (as well as the extension).
Git add all files in a folder
To add all files that live in a folder, use the following command:
git add folder_path_and_name/*
Example: in my project root, I have a folder called “assets” and this folder contains other folders & files. To stage or add all files & folders in this “asset” directory, I used the following command:
git add assets/*
git add all files in a sub-directory
If I want to stage only the “scripts” folder that lives inside the “assets“, the command will be as follows:
git add assets/scripts/*
It will stage all the files & other folders that live inside the “scripts” folder.
An alternative command for adding all files in a folder
In the last example, you saw that
git add folder_name/* command adds all files & folders in the stage. However, there is an alternative to this command as you see below.
git add .
Please note that this command (
git add .) works based on the current directory.
That means it adds all files from a folder where your cursor is currently pointing at.
Example: Let’s say, I want to add all files that live inside the “assets/scripts” folder. So my first step should be to change the directory in my terminal using the following command:
Now I am ready to use the
git add . (if I want to add all files that live inside the scripts folder)
If your terminal is currently pointing to the root directory and if you use the
git add ., this will stage all the changes that you made. In a nutshell,
git add . works very similar to the
git add -A. The only exception is
git add . works based on the directory where your terminal currently pointing at.
Learn more about Git
- What is Git and why it is used?
- How to install Git on Windows & Mac?
- How to use Git with Visual Studio Code?
- How to use Git and GitHub?
- What is the difference between Git and GitHub?
- How to connect local Git to a remote server?
- How to change Git remote origin URL?
- How to create a Git repository on GitHub?
- Git add all (stage all changes)
- How to undo the git add -A command?
- How to undo the last Git commit?
- How to change the git commit message?
- How to remove or unstage a file from Git commit?
- How to git push after rebase?
- Git switch branches: How to checkout the git branch?
- How to merge a git branch to master?
- Git branch: create, checkout, merge, list, command, delete & push
- How to clone a Git repository?
- How to git pull to override the local project?
- How to remove file from Git?
- When should you use git rebase?
- Git commands & explanation (downloadable cheatsheet included)
- How to create GitHub Pages?
In this post, I explained all sorts of information that you need to know about adding files, folders, specific files, all files in a sub-directory, etc. Also, I gave you supportive documents and other helpful resources to troubleshoot along the way. Therefore if you still have any questions about adding all files in Git, let me know.