mirbehroznoor / Basic-Magit-Tutorial

Basic Magit Tutorial for Git + Github in Emacs: Non-Expert Guidelines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Basic Magit Tutorial for Github

Learning Emacs

“There is no end, my friend” David Goggins

  • Some Knowledge of Emacs
  • Non-Expert Guidelines: Only for Personal Github
  • Always Beware of Changes: if there are changes in the remote main branch, fetch the changes before changing the local main or better, create a local branch of main and later, merge the changes.

Magit Push

  1. Create/Select a repository on Github
  2. Clone the Repo to your Local Computer M-x magit-clone
  3. Make your Changes or Add new files in Repo folder
  4. In the Repo, press C-x g or in minibuffer M-x magit-status
  5. Check If there are untracked or unstaged changes from files, press s to stage desired or all files.
  6. Better to split window before committing. It will automatically bring up the staged changes buffer and the committing buffer, easier to add comments.
  7. Once the status changed to staged, add commit (comments), press c (2x)
    • In Commit Section: press C-c C-c to save and finish, or press C-c C-k to cancel
  8. After committing, the M-x magit-status will show the commits in the Unmerged into x/y or Unpushed to x/y
  9. Press P to push changes then Press p to push main to upstream to the Github Repository.
    • In case of failure, try -F –force option with push main to
      • It can happen, if you are working on two repositories simultaneously which ever uses –force option will be worked on
  10. Depending on option, it can either ask for the SSH passphrase or Github username and password.
  11. Message in the minibuffer Git finished
  12. The magit-status shows section Recent Commits at the top the last commit made to the repository in Github. Press Tab to unfold the list of all recent commits

Magit Pull [Trial and Error]

  1. In the Repo, press C-x g or in minibuffer M-x magit-status
  2. If there are unstaged or uncommitted changes, M-x magit-reset-hard
  3. Once all cleared, go to the M-x magit-status buffer, press F either p or u to pull into main or master from origin/master or origin/main

Create a New Branch

Go to C-x g, Magit Status

Press b for Git Branch options

Press n to create a new Branch

Stackoverflow: Put Current Changes in a New Git Branch

Press b (2x) to switch to New Git Branch

Now, follow the normal process of pull or push to New Branch

Delete the New Branch

press C-x G magit status

press b for branch options

press k to delete the Branch

Yes Delete it Remotely + Locally

No Delete it Locally

About

Basic Magit Tutorial for Git + Github in Emacs: Non-Expert Guidelines

License:GNU General Public License v3.0