Skip to content

Instantly share code, notes, and snippets.

@NicktheGeek
Created May 11, 2022 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicktheGeek/7b934286dd312880e6da57c4e0e9e590 to your computer and use it in GitHub Desktop.
Save NicktheGeek/7b934286dd312880e6da57c4e0e9e590 to your computer and use it in GitHub Desktop.
git merge-staging
[alias]
; Pushes any work to current branch
; Sets the remote and the current branch programatically
; Sets the staging branch to second argument or default to develop
; Checks out the staging branch
; Pulls the remote work then pushes
; Checks out the original branch
merge-staging = "!f() { \
git push; \
REMOTE=`git remote`; \
echo $REMOTE; \
CURRENT=`git branch --show-current`; \
echo $CURRENT; \
STAGING=${1:-'develop'}; \
echo $STAGING; \
git checkout $STAGING; \
git pull; \
git pull $REMOTE $CURRENT; \
git push; \
git checkout $CURRENT; \
}; f"

git merge-staging

This is a git alias. To add it, edit you ~/.gitconfig file and add the code from lines 2-21 to the file after the [alias] line.

If the file has no [alias] line, start a new line and include the entire .gitconfig contents.

This adds a new command for git that will push up work, checkout the staging branch, pull down the work, and push it back to the staging branch before checking out the original branch.

This will allow a second argument like git merge-staging branch-name. In this case branch-name would be checked out instead of develop which is the default staging branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment