Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
`git-up` and `git-down`: A Rebase-centric Git Workflow

In my git development, I have an origin repository with a single branch that reflects our currently-deployed production code, and my own repository on my own machine. I develop features and bugfixes in their own branches. With help from several places around the internet (which I'm afraid I've forgotten), I've developed these git aliases to help smooth out my workflow.

    sync = "!f() { echo Syncing this branch with master && git checkout master && git pull --ff-only && git checkout - && git rebase --committer-date-is-author-date --preserve-merges master; }; f"
    release = "!f() { BRANCH=$(git rev-parse --abbrev-ref HEAD); FF=\"--no-ff\"; if [ $(git log --pretty=oneline master..HEAD | wc -l) -eq "1" ]; then FF="--ff"; fi; echo \"Sending changes from '$BRANCH' to origin. $FF\"; git checkout master && git merge $FF $BRANCH && ssh ORIGIN_SERVER 'cd ORIGIN_DIR && git pull --ff-only MY_REMOTE master'; }; f"

git sync will grab all changes from origin into master and then rebase your branch on top of that. I do this regularly during a long project to resolve any conflicts with upstream as soon after they occur as possible. I'm not entirely happy with how it handles dates on commits, even with the --committer-date-is-author-date option, but it has been good enough for me.

git release is run when you are ready to release code, and assumes that you've already done a git sync on the branch in question. If the branch is a single commit, it will perform a fast-forward merge with master, otherwise, it will make a merge commit. (I find this helps make history clearer as to when code was released vs. a feature in the middle of development.) Once the code is merged into your master branch, it will ssh to the server on which the origin repo lives and pull in the remote that you specify. (Most setups might use push in this instance, but, because we use the working directly on origin, that doesn't work well for us.)

And, of course, if you are looking for amusement, git sync can be renamed git up and git release can be renamed git down.

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