How to change repo with magit emacs?

Related searches

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.

You can call magit-status with prefix-arg (C-u), it will prompt you for git repository. So if you keybinding for magit-status is C-xg, you can do C-uC-xg, it will prompt for git repo.

You can also set the variable magit-repo-dirs to a directory (do C-hfmagit-repo-dirsRET to know more) and it will prompt you for all git repositories in magit-repo-dirs.

If you use projectile you can use the fact that it remembers your project directories and use it populate magit-repo-dirs, I have this in my init file to achieve this

(eval-after-load "projectile" 
  '(progn (setq magit-repo-dirs (mapcar (lambda (dir)
                                         (substring dir 0 -1))
                                       (remove-if-not (lambda (project)
                                                        (file-directory-p (concat project "/.git/"))) 

         (setq magit-repo-dirs-depth 1)))

The code above is executed after projectile is loaded. It gets the list of projects known to projectile by doing (projectile-relevant-known-projects), iterates through them and adds the projects that have .git/ folder to magit-repo-dirs, it also sets magit-repo-dirs-depth to 1 so magit looks for git repos only in the top directories.

Magit User Manual, Alternatively you can use an existing local repository, but if you do that, then you should commit all uncommitted changes before proceeding. To display� Then remove the upstream via command line: git remote remove upstream and add it again via magit M + a, type "upstream" as the remote name, and enter the repo path. It then give you the option of setting the new remote name "upstream" as the pushDefault .

I've found that if you use projectile, the easiest is to just set the following:

(setq projectile-switch-project-action 'projectile-vc)

Now you can use C-p p s (projectile-switch-project) and it will then immediately call projectile-vc, which if you have magit installed just calls magit-status in the project root. Simple!

Per-Repository Configuration (Magit User Manual), To clone a remote or local repository use C , which is bound to the command useful as it is not automatically updated when the HEAD of the remote changes. To do this, you want to create a new branch. With magit, you start a new branch in the status screen by choosing ‘b’ and then ‘n’. Choose where to start from and give a name to your new branch. Once the branch is created, you can change code, add files, remove files in the directory.

Getting Started (Magit User Manual), Installing from the Git Repository (Magit User Manual) git clone https://github. com/magit/magit.git ~/.emacs.d/site-lisp/magit $ cd ~/.emacs.d/site-lisp/magit it in some other directory using sudo make install and setting load-path accordingly . Magit depends on the dash, transientand with-editorlibraries which are available from Melpa and Melpa-Stable. Install them using M-x package-install RET <package> RET. Of course you may also install them manually from their repository.

Magit uses current working directory of your current buffer when you execute magit-status.


  1. Close magit current buffers (if any) (q)
  2. Change directory to the one with your repo (M-x cd)
  3. Start magit again (M-x magit-status)

Cloning Repository (Magit User Manual), 2.1 Installing from Melpa. Magit is available from Melpa and Melpa-Stable. If you haven’t used Emacs’ package manager before, then it is high time you familiarize yourself with it by reading the documentation in the Emacs manual, see (emacs)Packages.

Installing from the Git Repository (Magit User Manual), Magit is the most popular front end for Git. If you are new to Git and do not need support for other vcs this is likely the package you should try first. Egg (Emacs Got Git) is a fork of Magit. It currently isn’t very actively maintained. git-emacs is advertised as “yet another git mode on emacs for newbies”.