Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kbilsted
Last active May 2, 2020 16:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbilsted/8cd2507046764ed96305 to your computer and use it in GitHub Desktop.
Save kbilsted/8cd2507046764ed96305 to your computer and use it in GitHub Desktop.
Git guide for Hg users

A Git guide for Hg/Mercurial users

Delete stuff

  • hg uncommit / hg strip
  • git reset --hard HEAD~1

Combine stuff

  • hg combine xx (from xx to yy)
  • git reset --soft HEAD~3
  • git commit or
  • git rebase -i head~3

Rewrite history

  • git rebase -i HEAD~11

Move branch pointer

  • git branch -f branch-name new-tip-commit

Fetching stuff

  • hg pull
  • git fetch
  • hg pull + rebase
  • git pull

Fetch from upstream

(first time only)
git remote add upstream /url/to/original/repo 

git fetch upstream
git checkout master
git reset --hard upstream/master  

(when no changes on origin)
git push origin master --force

(when changes on origin)
git merge upstream/master

Deleting a branch locally and pushing delete up

git push origin --delete <branch>
git branch --delete <branch>

Deleting a local remote-tracking branch:

git fetch origin --prune

Merging PR on branch addMapToProjector onto new branch feature/foo from user janus project stateprinter

git checkout -b feature/foo master
git pull https://github.com/janus/stateprinter.git addMapToProjector
git push -u  "origin" refs/heads/feature/foo:refs/heads/feature/foo

nice Powershell functions

function unco()
{
	"git reset --soft head~1"
	git reset --soft head~1
}
function bundle($path)
{
	"git format-patch origin/master --stdout > c:\bundle\$path.diff"
	git format-patch origin/master --stdout > c:\bundle\$path.diff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment