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
Fork the target repository https://github.com/target/project
You can find the returned message has a merge request url.
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.
Add the target repository remote url
1 2 3 4 5
git remote add upstream `https://github.com/target/project` # Executes the `git remote`. The output: # # origin # upstream
Rebase the target repository to local
git pull upstream dev --rebase
Resolve all conflicts
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.
Force publish your code
git push -f origin feature-xxx
Then you will get a link from the result message that point to the MR page