Fastest way to merge branches via gitlab (or git)?

17,186

You can merge changes without going through a UI - this is one of the core functionalities of Git. Assuming you have two branches (development and production), here's how you would merge changes:

# Check out development branch
git checkout development

# Make changes, commit...
...

# Optional: Push development changes to the remote
git push origin development

# Check out production branch
git checkout production

# Merge the changes from the development branch
git merge development

# Push the changes to the remote
git push origin production

# Check out the development branch again
git checkout development

Now log into the production server and pull the changes there.

You could of course put the above checkout/merge/push steps into a script - that's quite common to do.

There are ways to automatically pull changes when something changes. Here are a couple of links for you:

Share:
17,186
Kyle Anderson
Author by

Kyle Anderson

Web Developer. Systems Architect. Currently managing a few SAAS services using PHP, Jquery, Javascript, Nginx, Linux, Mongo, Gearman, Supervisord, ReactPHP. All custom everything.

Updated on July 19, 2022

Comments

  • Kyle Anderson
    Kyle Anderson almost 2 years

    I have a development branch and a production branch. I push changes from my development server to a remote gitlab install. Then I login to gitlab GUI and do a merge request (which is quite time consuming). Then I "git pull origin production" from my production server.

    The merge request step kind of takes a long time to do. Is there a faster way to do this? Could I just make a bash/shell script to merge development into production and pull down the updates with one command? If so what commands is this merge request running?

    I make merge requests a couple times a day. Anything to speed up the process I have would be great.

  • Kyle Anderson
    Kyle Anderson almost 9 years
    Worked like a charm. Thanks.
  • Kyle Anderson
    Kyle Anderson almost 9 years
    Before I merged, I had to create the local production repo and pull in the remote repo first since it didnt exist locally with $ git branch production; git checkout production; git pull origin production;