I need to work with a few different git repositories. How to switch between them using magit? Magit allows me to choose a directory when I just start it.. But it is not clear for me how to switch to another repo if required. I've looked at magit cheatsheet and docs but haven't found an answer. Thanks.
magit have changed a few things, so here is an updated version that worked for me in 2024 of the accepted answer
(let ((depth 1)) ;; set the depth of where .git will be at the deepest to 1, i.e. somesubproject/.git/ and .git/ will be searched. if set to 0, only .git/ directly after root will be listed
(eval-after-load "projectile"
'(progn (setq magit-repository-directories (mapcar (lambda (dir)
(cons (substring dir 0 -1) depth)
)
(remove-if-not (lambda (project)
(file-directory-p (concat project "/.git/")))
projectile-known-projects))))
)))
The things changed:
magit-repo-dirs
changed to magit-repositories-directories
, and the schema of the variable changed to a list of element with (DIRECTORY . DEPTH)
form, where depth refers maximum depth to scan of .git/
, start with 1, with .git/
directly under rootmagit-list-repositories
command. it uses magit-repositories-directories
, and that gives a more detailed buffer for you to choose repos from(including name, version and path).edit: I changed from (projectile-relevent-known-projects)
to projectile-known-projects
. the former don't include some projects, such as the current one.