How to Commit a Merge Request?

What ever we use the component development or contribute a code to an open source project, I recommend using the rebase to keep our git tree clear. There are some troubles when I use the rebase command in my work that I need note them here.

The steps to commit a merge request

  1. Fork the target repository
  2. Yourself forked repository
  3. Clone yourself repository to local.
git clone origin
  1. Checkout a new branch feature-xxx
git checkout -b feature-xxx
  1. Write code in this branch.
  2. Commit your code.
git add .
git commit -m "message"
  1. Push your new commit to your remote repository.
git push origin feature-xxx
  1. You can find the returned message has a merge request url.
  2. Open the link that you can commit a merge request to the target repository.

Sync the target repository to local

Sometimes you need a long time to develope the new features and the target repository might accept other merge requests in this period. You commit a MR this moment directly most likely occurs conflicting.

Usually, we would multiple merge the target repository to sync our local code. All the merge logs will be recorded in our git tree and these insignificant merge records will dirty our git history.

Fortunately, the git provides a rebase command can resolve the trouble we met. Using rebase can pull all commits from the target repository to local without any rebase logs.

  1. Add the target repository remote url
git remote add upstream ``
# Executes the `git remote`. The output:
# origin
# upstream
  1. Rebase the target repository to local
git pull upstream dev --rebase
  1. Resolve all conflicts
  2. Push you code to your remote repository
git push origin feature-xxx

Then, you would get an error that requires you git pull origin feature-xxx fist.
Don’t do this. If you execute this command you will get a chaotic git records and then you can only recreate a new MR to fix it.

To resolve this problem is very easy that you need to add a -f flag to your push command. The -f means force publishing. Don’t worry that the force publishing would break your code, it’s ok.

  1. Force publish your code
git push -f origin feature-xxx
  1. Then you will get a link from the result message that point to the MR page