66

What is the Magit equivalent ofgit add [--intent-to-add] <filename> for checking a newly created file into Git?

askedSep 2, 2015 at 20:54
feoh's user avatar
3
  • At some point, perhaps someone will put together a cheat-sheet that converts command line options (in alphabetical order) to magical Magit keboard shortcuts. It should not be necessary (in my opinion) to read the manual -- that is why G*d created an index -- i.e., read just whatever is relevant to the task at hand.CommentedSep 3, 2015 at 2:01
  • 1
    It doesn't map command line to magit, but there is a refcard:magit.vc/manual/magit-refcard.pdf.CommentedSep 3, 2015 at 15:00
  • @tarsius: It would be sensible to add a "git add" index entry pointing to the "Staging and Unstaging" node of the manual.CommentedJun 21, 2017 at 23:54

3 Answers3

70

To stage a change presss with point on any "stageable change". This includes files listed below "Untracked files" and "Unstaged changes".

You can also expand the files below "Unstaged files" usingTAB (also works for many other sections) to see the hunks. You can then stage an individual hunk, again by pressings while point is inside it.

You can even stage just parts of a hunk using the region. To do that pressC-SPC to mark the beginning of the region and thenn a few times to move to where the region should end.

In order togit add --intent-to-add, useC-u s.

You can also unstage, discard, reverse, and apply changes in a similar fashion. This is described in more detail in the manual. In particular seeStaging and unstaging,Applying, andSections. Staging is also covered inGetting Started.

answeredSep 2, 2015 at 22:04
tarsius's user avatar
6
  • 6
    s will stage a file. But how can i just add file, so that git will start tracking file but not stage all changes?CommentedNov 12, 2015 at 11:48
  • 9
    @ChillarAnand You can now do that usingC-u s.CommentedMay 24, 2016 at 22:24
  • 2
    When the git config "showUntrackedFiles = no" is set, staging with "s" is not possible as the files are not displayed. In that case @glucas answer is the way to go. i.e "magit-stage-file". For those who are wondering why would someone disabled tracking files, the workflow is common when the main repo is managed by some other vc like perforce and git is used as a local vc within the vc then in such scenario disabling tracking speeds up significantlyCommentedJan 17, 2020 at 9:29
  • How to add all untracked files at once?CommentedFeb 2, 2021 at 4:06
  • Presss while point is on the section title "Untracked files".CommentedFeb 2, 2021 at 9:02
13

Start withmagit-status, then move to the file name under the "Untracked files" heading and hits to stage it.

12

If what you're looking for is a way to add/stage a file directly from its buffer: try the commandmagit-stage-file. If you do that a lot you could bind it to a key.

As others have already pointed out, the more common way to stage/add files is from themagit-status buffer.

answeredSep 3, 2015 at 15:10
glucas's user avatar
3
  • magit-stage-file asks for file to stage. Doesn't directly stage itCommentedSep 5, 2017 at 15:52
  • That's not how it behaves for me. Also from the doc: "With a prefix argument or when there is no file at point ask for the file to be staged. Otherwise stage the file at point without requiring confirmation."CommentedSep 5, 2017 at 15:54
  • Ah, I see: For a new file it does in fact prompt. If the file already exists (and you are staging changes) it does so silently. Thanks for pointing that out.CommentedSep 5, 2017 at 15:59

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.