JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Git add folder

Author:JIYIK Last Updated:2025/03/27 Views:

git addUsed to add specific folders and files. This tutorial will handle it in a modern way git add <folder>.


git addAdd all or specific folders and files to staging in Git using

Use the following syntax to add files:

git add <file>

Use the following syntax to add a folder:

git add folder1/

or

git add folder1

For older versions of git, add --allthe -p flag and add it at the end of the folder name 正斜杠.

git add --all <folder>/

For example:

git add --all folder1/

Create a project folder in Git containing 2 folders and files for testinggit add

First, create a folder using the following command:

mkdir project-folder

To go into the folder, use the bash code.

cd project-folder

In the project folder, open Git Bash.

git init

Initialized empty Git repository in C:/You/Documents/project-folder/.git/

This will initialize a git working tree. Create two new folders in the project folder and name them Folder1 and Folder2.

In folder1, add a text document and name it text1.txt.

To create the file, run the following command:

touch text1.txt

On Git Bash, run the following code:

git status

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        folder1/
        folder2/

nothing added to commit but untracked files present (use "git add" to track)

folder1/and folder2/are untracked files and folders that are not included in the files and folders that are ready for commit.

Suppose we want to add it separately folder2/. We will add it and folder1 will not be staged.

git add --all folder2/

or

git add folder2

Check the status.

git status

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   folder2/text1.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        folder1/

folder2/text1.txtThe files and folders are now added to the staging content. The untracked folders arefolder1/.

.It also means all, but is not equivalent to --all.

Run git add . folder2/instead git add --all folder2/. We put folder2 back into unstaged and stage it again for testing.

git restore --staged .

or

git rm --cached folder2/ -r

Let's check the status;

git status

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        folder1/
        folder2/

nothing added to commit but untracked files present (use "git add" to track)

Now that all folders are untracked, we can test the code ..

git add . folder2/
git status

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   folder1/text1.txt
        new file:   folder2/text1.txt

Two of them are added as .Applies to all files and folders.

So don't use .and expect stage specific folders. Use --all, git add --all folder2/e.g.


in conclusion

Adding a folder is basically the same as adding a file. Now we can run git add <folder>or git add <folder>/to cherry-pick the folder to stash.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Adding files in Git

Publish Date:2025/03/27 Views:74 Category:Git

This article will discuss different ways to add files to our repository on Git. In Git, use git add the command to add all files We can git add add all the files without exception using the command as shown below. git add -A -A The -p param

Different ways to add files to staging with Git

Publish Date:2025/03/27 Views:199 Category:Git

While the command git add is probably the most commonly used command for adding files to your stash, other flags may come in handy depending on the situation. This article takes a deep dive into git add the flags you can use with the comman

Git synchronizes branches with Master

Publish Date:2025/03/27 Views:61 Category:Git

Git is a well-organized distributed version control system that can be very effective in managing source code in a distributed team of developers. When different developers are working on different product features, once they have completed

Setting Upstream in Git

Publish Date:2025/03/26 Views:152 Category:Git

In this article, we will learn how to use in Git upstream . When using Git by cloning and creating new repositories in branches, we must set up upstream branches for future commits and fetches. But first, we should understand what is upstre

Add Git to PATH on Windows

Publish Date:2025/03/26 Views:92 Category:Git

Git is a free and open source version control system designed to work with projects quickly and efficiently. You can use it on Windows, Mac, and Linux operating systems. This article explains how to add git to your Windows PATH environment

Open a file in Git Bash

Publish Date:2025/03/26 Views:68 Category:Git

We cannot use open in Git Bash. If you try to open a file using open on Git Bash, you will get the error bash: open: command not found . This short article explains how to open a file on Git Bash for Windows. Open a file in Git Bash We can

Creating Git patches from uncommitted changes

Publish Date:2025/03/26 Views:91 Category:Git

This article explains how we can create a Git patch from uncommitted changes in our working directory. This is handy when we want to create a patch without creating a commit. Creating Git patches from uncommitted changes We will use an exam

How to uninstall git in Windows

Publish Date:2025/03/26 Views:187 Category:Git

Git for Windows is a well-known and user-friendly software that provides a smooth platform to easily use Git in a team-friendly environment. Sometimes we want to get rid of some software because of space reasons, or the software is not comp

How to check the Git version

Publish Date:2025/03/26 Views:130 Category:Git

Git is primarily known as a unique free source code distributed version control system that can easily store all kinds of projects, big or small. Any new developer or someone who is new to it can understand it quickly and easily. We can ins

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial