Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Agreed, and here's a git alias I made for the occasion:

  merge-pr = "!f() { git fetch $1 $2; git branch _FETCH_HEAD FETCH_HEAD && git rebase HEAD _FETCH_HEAD && git checkout master && git merge --ff-only _FETCH_HEAD; git branch -d _FETCH_HEAD; }; f"
Syntax: `git merge-pr <remote> <branch>`. You can copypaste url + branch from github's UI above the merge button.

Note: This merges only to master, no way to specify another merge target. Feel free to suggest improvements.



I have these for merging a PR into develop and master respectively. Usage is `git pr <#>`

  pr  = "!f() { git checkout develop && git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1 && git rebase -i origin/develop && git checkout develop && git merge - && git push; }; f"
  prm  = "!f() { git checkout master && git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1 && git rebase -i origin/master && git checkout master && git merge - && git push; }; f"


I remember trying and failing to get exactly that working. I'll give yours a shot, thanks!


Here are mine, helpful colors and error message included.

  sync = "!f() { echo \"$(tput setaf 4)Syncing this branch with origin master$(tput sgr 0)\" && git fetch origin master && git rebase origin/master && echo \"$(tput setaf 2)Branch sync successful$(tput sgr 0)\"; }; f"

  ship = "!f() { echo \"$(tput setaf 4)Shipping this branch to master$(tput sgr 0)\" && git checkout master && (git merge --ff-only - || (echo \"$(tput setaf 1)Could not merge branch into local master\\nRun git sync before running this command\\nIf this error persists, you have local, un-pushed commits in your master branch\\nPush them to origin master or move them into a branch before running this command$(tput sgr 0)\"; git checkout -; return 1)) && (git push origin master || (echo \"$(tput setaf 1)Could not push branch\\nRun git sync before running this command$(tput sgr 0)\"; git reset --hard HEAD@{1}; git checkout -; return 1)) && echo \"$(tput setaf 2)Branch ship successful$(tput sgr 0)\"; }; f"
The reason they are separate is so that you can

  git push --force-with-lease origin HEAD:<remote-branch-name>
in between. This way, GitHub marks the PR as "Merged" instead of "Closed with unmerged commits". It's a minor detail, but I like it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: