Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 544
Kyle Anderson Avatar asked Jul 29 '15 20:07

Kyle Anderson


People also ask

How do I merge branches in GitLab?

A developer must log into the GitLab web application and create a merge request, specify the branch they're working on as the source and the master branch as the target. A user with rights to merge or push into the master branch is then set as the “assignee” before the merge request is initiated.

What is Fast Forward merge in GitLab?

Fast forward merge can be performed when there is a direct linear path from the source branch to the target branch. In fast-forward merge, git simply moves the source branch pointer to the target branch pointer without creating an extra merge commit.

What is the safest and fastest way to combine commits from two different branches?

The git merge command integrates the independent lines of development into a single branch. The command is used to combine two branches and also to merge multiple commits into one history. Once you make changes in the local repository and ready to share it with your team members, then execute git push.

What git strategies are used to merge two branches?

Recursive. This operates on two heads. Recursive is the default merge strategy when pulling or merging one branch. Additionally this can detect and handle merges involving renames, but currently cannot make use of detected copies.


1 Answers

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:

  • Git: auto pull from repository?
  • https://johnflynn.me/autodeploy-your-gitlab-projects/
like image 186
nwinkler Avatar answered Oct 25 '22 17:10

nwinkler