Windows 10, Emacs 25.1 , Magit
I have many git repositories.
Does the notion of the currently selected repository exist in Magit?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityWindows 10, Emacs 25.1 , Magit
I have many git repositories.
Does the notion of the currently selected repository exist in Magit?
Yes, Magit knows what the current repository is. That means that you can, for example, have multiple status buffers, each showing the status of a certain repository. When you invoke magit-status
, Magit will automatically show the status for the current repository, either creating a new buffer or switching to an existing buffer for that repository.
The current repository is determined by asking Git what the repository for the buffer-local value of default-directory
is. So you can invoke a Magit command and it will always do its thing in the right repository, i.e. in the directory the current buffer "is in". Like in a shell where git
also acts on the current repository based on the shell's working directory ($PWD
).
If the default-directory
is not located inside a Git repository then you will likely get an error. Some commands will instead ask about creating a new repository or switching to an existing repository.
If you need that information programmatically, then you can use the function magit-toplevel
to get the top-level directory of the current repository's working directory. Or you can use magit-git-dir
to get the location of the .git
directory (which might be located outside the working tree).