Skip to content

Instantly share code, notes, and snippets.

@afrieirham
Last active Apr 30, 2021
Embed
What would you like to do?
Git guide

Remove git remote reference

  • git remote rm <destination>

If something went wrong

Use these commands if you made any mistakes. Accidental commits, wrong git message (or typo).

Update previous git message (or typo)

  • git commit --amend or
  • git commit --amend -m "New git message"

Undo previous commit

  • git reset --soft HEAD~1 (make sure working directory is clean: use git stash)

What is git stash?

Git stash is a way to temporarily save your work without committing. This is helpful when you're in a middle of changes but you want to switch branch or maybe after doing some work you realised that you were in the wrong branch.

Save a stash

  • git stash save "<Save name>"

Save a stash (including new files)

  • git stash save "<Save name> -u"

List all stash

  • git stash list

It will show something like this

stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
stash@{1}: On master: 9cc0589... Add git-stash

Apply stash

  • Apply stash but won't drop it
  • n = stash index
  • git stash apply stash@{n}

Pop stash

  • Apply stash and drop it
  • It will apply and drop stash@{0} everytime
  • git stash pop

Drop stash

  • n = stash index
  • git stash drop stash@{n}

Drop all stash (dangerous action)

  • git stash clear

Sync with original repo (after forked)

  • git fetch upstream to get latest changes from original repo
  • git merge upstream/<branch-name> origin/<branc-name> merge with local repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment