24

I normally use only a few git commands each time I want to commit changes to a repository:

$ git add --all .
$ git commit -m "update."
$ git push -u origin master

Can magit be useful in this regard? M-x magit-status seems helpful but I am not fulling understanding the language of "staging/unstaging" "hunks" etc. from ref1 ref2 ref3.

What might be the equivalent commands in magit? Thanks in advance -

Edit This page seems to speak better to my level but is C-u s the equivalent of git add --all .? Though that page says it does not work.

1
  • For simple git use, the vc-mode commands are perfectly suitable. I do use magit for complex commits etc., but for simple cases vc is excellent.
    – éric
    Jan 9, 2021 at 13:03

3 Answers 3

44
  • S stages all files
  • c c initiates a commit. Write the message and then press C-c C-c to actually create the commit.
  • P u pushes to the upstream branch. In the popup that appears after you have pressed P you can see the upstream. If the upstream is not set yet, then you can still use P u. You'll be asked for a branch which is then configured as the upstream before pushing.
1
  • It took me some time to figure out what to actually provide after pressing P u when the upstream is not yet set. In case your remote repository has the shortcut name origin as set in .git/config as [remote "origin"] and if your branch is called my-new-feature then you need to type origin/my-new-feature into the minibuffer after P u.
    – Harald
    Oct 23, 2023 at 7:27
2

This one is also quite easy technique without learning shortcuts of magit by using hydra.

(defhydra yt-hydra/help (:color blue :hint nil)
  "
_mp_ magit-push #_mc_ magit-commit #_md_ magit diff #_mla_ magit diff #_mla_ magit status
"
  ;;Magit part
  ("mp" magit-push)
  ("mc" magit-commit)
  ("md" magit-diff)
  ("mla" magit-log-all)
  ("ms" magit-status)
  )
(global-set-key (kbd "<f1>") 'yt-hydra/help/body)
1

I just write an easy shell function to help PUSHING ALL.

function lazy-git {
    git add -A
    git commit -a -m "🍁  $1"
    git push
}

lazy-git "Update somethinng"

or in Emacs

(defun push-all (comment)
  (interactive (list
            (read-string (format "🔥 Push for [%s]: " (current-directory-name)))))
  (save-some-buffers t) ; save all buffer
  (shell-command (format "git add -A; git commit -a -m \" %s\"; git push &"
                     comment)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.