My team shares a "work" branch and a "stable" branch. Whenever a particular work branch is approved for further testing/release/etc, we merge it into stable. No code is ever checked directly into the stable branch.

Because of this, merge conflicts simply won't happen, and it seems silly to pull down the work branch and the stable branch, merge them, and then push the changes back. Is there a git command to ask a remote git server to commit a merge of two branches that it already knows about?

  • 4
    You seem to be implying that pulling down both branches will involve a lot of data transfer or effort, but that isn't actually true -- the stable branch and the work branch contain the same commits. If you have a copy of the work branch then the only extra data you need to have a copy of the stable branch is the sha1 hash of its tip. And if you don't have the work branch, then how can you make any sensible edits to the repository contents? – John Bartholomew Jun 15 '12 at 19:34
  • The merge you are describing is a very standard way of using git, and git should keep all known branch states up to date. As John says, it's not that much data really. – MarkJL Sep 6 '17 at 14:39

It's kinda in the nature of a DVCS that the action happens on a local machine, and gets pushed back to the main repo.

If it's that onerous, script it.


if [ ! -f ".git" ]
  echo "Not in a git repo!" >&2
  exit 1
  git checkout stable && \
  git pull origin stable && \
  git merge work && \
  git push origin stable
| improve this answer | |
  • I assumed as much, but I figured there might just be a way. Thanks! – Brandon Yarbrough Jun 15 '12 at 19:19
  • @CaptainAwesomePants There may be some git extensions/add-ons for doing this, but they're usually just a bunch of bash (or python, or ruby) hacks that do almost the same thing. Gitlab has a 'merge request' feature that might be what you want, if you wanted a web interface. But generally, scripting is the easiest way to simplify your git workflow. – Jason Lewis Jun 15 '12 at 22:21

Yes - by using SSH. Just SSH into the server containing the repo. If you have permissions to write to the repository and execute git, then just cd into the repository's directory and run the git merge command.

| improve this answer | |
  • 5
    Server-side repos are usually (and should be) 'bare' repos, so commits and merges are typically either impossible or terrible ideas. – Jason Lewis Jun 15 '12 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.