🥋
Dojo
Inglés
Inglés
  • Dojo
    • 🔎Relevant content
  • App Store
    • Create an Apple Developer Account
    • Create Organizational Account on Apple Developer
    • Upload an App to the App Store
  • Classroom
    • Create a class in Classroom
    • Create and add topics to a Classroom class
    • Add students or teachers in Classroom
    • Assign trainings in Classroom
    • Join a Classroom class as a student
  • Docker
    • Install Docker
  • Git
    • Do a 3-way merge in git
    • Do a Fast Forward merge in git
    • Do a git revert
    • Resolve merge conflicts using the command line
    • Use git add
    • Use git cherry pick
    • Use git rm
    • Use git stash
  • Git Graph
    • Install Git Graph
    • See repository graph
    • Filter branches
    • Merge branch
  • GitBook
    • Create Dojo content in GitBook
    • Create a space in GitBook
    • Delete a space in GitBook
    • Duplicate a space in GitBook
    • Move a space in GitBook
  • GitLab
    • Create a milestone in GitLab
    • View a milestone in GitLab
    • Close a milestone in GitLab
    • Create a repository in GitLab
    • Import issues to GitLab
    • Make a bulk in GitLab
    • Setup two factor authentication for GitLab
    • Create a task in GitLab
    • Viewing tasks in GitLab
    • Close tasks in GitLab
  • Gmail
    • Create a Gmail signature
    • Create an email template in Gmail
    • Send emails with different aliases or groupse
    • Get permissions to send and receive emails from an alias or group
  • HUGO
    • Organize Markdown Content
  • Java
    • Install Java with SDKMan
  • Jira
    • Use shortcuts in jira
    • Use basic filters in jira
    • Use advanced filters in jira
    • Use filters in jira projects
  • Kubernetes
    • Deploy a microservice in Kubernetes
    • See Kubernetes Pod Logs
    • Run a pod with images from a private repository
    • Use config maps to configure a deployment
    • Use secrets to configure a deployment
    • Communicate two microservices in a Kubernetes cluster
    • Create an Ingress Controller on a Cluster
    • Configure Kubernetes Horizontal Pod Autoscaler
    • Connect a container to Google Storage
  • Make
    • Install Make
  • Minikube
    • Install Minikube
    • Manage Cluster With Minikube
    • Use Minikube to Configure a Kubernetes Cluster
  • MySQL
    • Dump a database in MySQL
    • Install MySQL with Docker container
  • Node.js
    • Install Gray-matter
    • Use Gray-matter
    • Read File in Node.js
  • Open SSH
    • Generate SSH private-public key pair
  • Play Store
    • Upload an App to the Google Play Store
    • Create organizational account in Play store
  • Screen Recorder
    • Loom
      • Install Loom
      • Record with Loom
  • Tezos
    • Deploy a smart contract
    • Implement a NFT contract
    • Interact with a smart contract with Taquito
  • Telegram
    • Forward messages to multiple users
  • VaultWarden
    • Create an account
    • How can I create a password?
    • Sharing credentials with external parties
  • Video editor
    • HandBrake
      • Change the format of a video in HandBrake
    • iMovie
      • Edit video in iMovie
  • Visual Studio Code
    • Install visual studio code
    • Install extensions in vscode
  • VueJS
    • Create a project with Vue
    • Install VueCLI
  • YouTube
    • Upload a video to YouTube
  • Zoho
    • Share access from zoho
    • Remove access from zoho
    • Login to the dojo base with a shared access by zoho
Powered by GitBook
On this page
  • Options
  • Common options
  • Examples
  • Reference links
  1. Git

Use git add

git-add - Add file contents to the index

This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. It typically adds the current content of existing paths as a whole, but with some options it can also be used to add content with only part of the changes made to the working tree files applied, or remove paths that do not exist in the working tree anymore.

Options

<pathspec>…​

Files to add content from. Fileglobs (e.g. *.c) can be given to add all matching files. Also a leading directory name (e.g. dir to add dir/file1 and dir/file2) can be given to update the index to match the current state of the directory as a whole (e.g. specifying dir will record not just a file dir/file1 modified in the working tree, a file dir/file2 added to the working tree, but also a file dir/file3 removed from the working tree).

Older versions of Git used to ignore removed files; use --no-all option if you want to add modified or new files but ignore removed ones.

-n --dry-run

Don’t actually add the file(s), just show if they exist and/or will be ignored.

-v --verbose

Be verbose.

-f --force

Allow adding otherwise ignored files.

--sparse

Allow updating index entries outside of the sparse-checkout cone. Normally, git add refuses to update index entries whose paths do not fit within the sparse-checkout cone, since those files might be removed from the working tree without warning.

-i --interactive

Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to a subset of the working tree.

-p --patch

Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.

This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand.

-e --edit

Open the diff vs. the index in an editor and let the user edit it. After the editor was closed, adjust the hunk headers and apply the patch to the index.

The intent of this option is to pick and choose lines of the patch to apply, or even to modify the contents of lines to be staged. This can be quicker and more flexible than using the interactive hunk selector. However, it is easy to confuse oneself and create a patch that does not apply to the index.

-u --update

Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.

If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories).

-A --all --no-ignore-removal

Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.

If no <pathspec> is given when -A option is used, all files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories).

--no-all --ignore-removal

Update the index by adding new files that are unknown to the index and files modified in the working tree, but ignore files that have been removed from the working tree. This option is a no-op when no <pathspec> is used.

This option is primarily to help users who are used to older versions of Git, whose "git add <pathspec>…​" was a synonym for "git add --no-all <pathspec>…​", i.e. ignored removed files.

-N --intent-to-add

Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This is useful for, among other things, showing the unstaged content of such files with git diff and committing them with git commit -a.

--refresh

Don’t add the file(s), but only refresh their stat() information in the index.

--ignore-errors

If some files could not be added because of errors indexing them, do not abort the operation, but continue adding the others. The command shall still exit with non-zero status. The configuration variable add.ignoreErrors can be set to true to make this the default behaviour.

--ignore-missing

This option can only be used together with --dry-run. By using this option the user can check if any of the given files would be ignored, no matter if they are already present in the work tree or not.

--no-warn-embedded-repo

By default, git add will warn when adding an embedded repository to the index without using git submodule add to create an entry in .gitmodules. This option will suppress the warning (e.g., if you are manually performing operations on submodules).

--renormalize

Apply the "clean" process freshly to all tracked files to forcibly add them again to the index. This is useful after changing core.autocrlf configuration or the text attribute in order to correct files added with wrong CRLF/LF line endings. This option implies -u. Lone CR characters are untouched, thus while a CRLF cleans to LF, a CRCRLF sequence is only partially cleaned to CRLF.

--chmod=(+|-)x

Override the executable bit of the added files. The executable bit is only changed in the index, the files on disk are left unchanged.

--pathspec-from-file=<file>

--pathspec-file-nul

Only meaningful with --pathspec-from-file. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes).

--

This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options).

Common options

git add <file>

Stage all changes in <file> for the next commit.

git add <directory>

Stage all changes in <directory> for the next commit.

git add -p

Begin an interactive staging session that lets you choose portions of a file to add to the next commit. This will present you with a chunk of changes and prompt you for a command. Use y to stage the chunk, n to ignore the chunk, s to split it into smaller chunks, e to manually edit the chunk, and q to exit.

Examples

  • Adds content from all *.txt files under Documentation directory and its subdirectories:

    $ git add Documentation/\*.txt

    Note that the asterisk * is quoted from the shell in this example; this lets the command include the files from subdirectories of Documentation/ directory.

  • Considers adding content from all git-*.sh scripts:

    $ git add git-*.sh

    Because this example lets the shell expand the asterisk (i.e. you are listing the files explicitly), it does not consider subdir/git-foo.sh.

  • When you’re starting a new project, git add serves the same function as svn import. To create an initial commit of the current directory, use the following two commands:

    git add .
    git commit

    Once you’ve got your project up-and-running, new files can be added by passing the path to git add:

    git add hello.py
    git commit

    The above commands can also be used to record changes to existing files. Again, Git doesn’t differentiate between staging changes in new files vs. changes in files that have already been added to the repository.

Reference links

PreviousResolve merge conflicts using the command lineNextUse git cherry pick

Last updated 1 year ago

Pathspec is passed in <file> instead of commandline args. If <file> is exactly - then standard input is used. Pathspec elements are separated by LF or CR/LF. Pathspec elements can be quoted as explained for the configuration variable core.quotePath (see ). See also --pathspec-file-nul and global --literal-pathspecs.

git-config[1]
https://git-scm.com/docs/git-add/en
https://www.atlassian.com/git/tutorials/saving-changes