Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Adding files to the repository

Header Image

Ahoy matey! So ye want to learn how to add files to yer Git repository, do ye? Well, ye’ve come to the right place. Adding files is an essential part of using Git, and it’s an easy process once ye get the hang of it.

Adding files to be tracked by Git

Before ye can add a file to yer Git repository, ye need to make sure that Git is tracking it. In Git, tracked files are files that Git knows about and will include in yer repository’s commit history. Untracked files are files that Git doesn’t know about and will not be included in yer repository’s commit history.

To add a file to be tracked by Git, ye can use the git add command. For example, let’s say ye have a file called treasure_map.txt that ye want to add to yer repository. Ye can add the file to be tracked by Git with the following command:

git add treasure_map.txt

This tells Git to start tracking the treasure_map.txt file and include it in yer repository’s commit history.

But wait, there’s more! Ye can also use the git add command to add multiple files at once. Let’s say ye have two files, rum_recipe.txt and parrot_selfie.jpg, that ye want to add to yer repository. Ye can add both files to be tracked by Git with the following command:

git add rum_recipe.txt parrot_selfie.jpg

Now, both rum_recipe.txt and parrot_selfie.jpg are being tracked by Git and will be included in yer repository’s commit history.

But what if ye have a lot of files to add? Ye don’t want to have to list them all out one by one. Don’t worry, matey! Git has ye covered. Ye can use the git add . command to add all files in the current directory to be tracked by Git.

git add .

This tells Git to add all files in the current directory to be tracked by Git.

Conclusion

Well done, matey! Ye now know how to add files to be tracked by Git. Remember, tracked files are files that Git knows about and will include in yer repository’s commit history. Untracked files are files that Git doesn’t know about and will not be included in yer repository’s commit history. So, always make sure to add yer files to be tracked by Git before ye commit yer changes. Keep practicing and soon ye’ll be a Git master!