Oscar the owl and Vershd logo
Make Git add files to a commit

Make Git Add Files to a Commit

28th August 2020

This is part of a Git Tips series. For the complete set for beginner and intermediate Git users, see our white paper.

The Problem

If you’ve got multiple files to add (stage), and you’re working to a deadline, you’ll want to know how to add files to Git commit as quickly and simply as possible, and quite possibly how to add all files to Git commit.

You can add files one by one to prevent any costly mistakes. But if you know what you’re doing understanding how to add all files at once can streamline your workflow and speed up deployment.

As is the often the case with Git there are several different ways to add all files ready for commit, with slight differences in each command. We’ll explain them all.

Information: we assume you’re working with Git version 2.x with these commands.

Add All Modified Files

The quickest way to add all the modified files you’ve been working on to your local repo is with the update command:
git add -u
The -u is shorthand for --update. But this command will only stage modified and deleted files.

Add All New, Modified & Deleted Files

There are two command options to add all new, modified and deleted files. You can use:
git add -A
git add .
The difference is where the staged files are sourced from.

git add . will only add files located in the current path you’re working in. So, if you’re in a root directory, it will only add files located there, and not any sub directories.

So the best option to add all files is git add –A. The -A is shorthand for --all, it will find all files from every directory in your project and stage them all.

Warning: this command will also update deleted files and remove them from staging.

Add All New & Modified but Not Deleted Files

If you want to keep files in your repository even if they no longer exist in your local directory, you’ll need to use a different command to add all new and modified files:
git add --ignore-removal
It does what it says on the tin and ignores any files that have been removed/deleted.

Commit the Staged Files

Using the above commands, you’ll have added all files in your directory to staging, ready for commit. Now it’s simply a case of using the standard git commit command:
git commit -m "your message"
And all your files have now been committed. If you want to add and commit all tracked, modified files in a single command you could use:
git commit -am "your message"
However, this command will only add and commit all modified files. It does not add any newly created files. So the best option if you want to add all files to Git Commit, is to use the following two commands:
git add -A
git commit -m "your message"
Or you can use them as a single command line in the following way, if you want to minimise entries:
git add -A && git commit -m "your Message"

Commit the Staged Files Using an Alias

The only minor problem you may find with the above command line is that it’s long winded. Typing it out repeatedly could slow your workflow down. So, the alternative option is to create your own alias. All you need to do is set up your own shorthand for multi-command lines:

• Open up your home directory
• Located your git.config file
• Add the following command xx = !git add -A && git commit -m
• Replace xx with your desired alias, and you’re done.

Now all you have to do when you want to add and commit all files (including new ones) in a single command is type:
git xx "your message"
Simple and effective. In general, Git commits should be regular and modular, preferably affecting only a few files, otherwise you may run into accidental deletions and unwanted errors.

The Quickest & Easiest Solution

Do you need a Git GUI that's totally free for personal use? Vershd boosts your software development productivity by making Git simple with a unique UI/UX. It's a Git GUI that prevents errors and creates clarity. This Git client soars over your repository and then swoops down to quickly tackle branches, commits and files. It deals with Git, so you can concentrate on coding.

Get screenshots and a 60 second video of what Vershd, the effortless Git GUI can do for you.
Vershd is the effortless Git GUI for Windows, Mac, & Linux
Oscar the owl and Vershd logo
 © 2021 Blightysoft
Made in England
St. George's flag of EnglandThe Union Jack, the flag of the United KingdomThe European Union flagThe United Nations flag
chevron-right linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram