Domanda

I am reading about git rebase workflow and I think I get the basic idea, but my problem is that all the tutorials that I stumbled upon don't discuss the situation where you have something like this:

  1. Update local repository with changes from remote repository, create feature branch.
  2. Hack away on feature branch
  3. Update master with changes from remote repository (for example wtih git pull on master)
  4. Rebase feature branch onto master
  5. Merge master with feature branch (this should result in fast-forward)
  6. Push changes to remote and receive an error, someone else has pushed onto master

Now what should be done if we still want to preserve fully linear history on master branch without merge commits?

If I am not mistaken I should perform git pull --rebase and then try pushing, but if this is the answer is it possible to do rebase workflow only from IDEAlevel (normal git pull will result in merge commit because of commits that were pushed by someone else)? Looking at the manual: https://www.jetbrains.com/idea/webhelp/pull-changes-dialog.html there is no option for rebasing in pull dialog.

È stato utile?

Soluzione

I think that after doing 4 you will not merge but rebase the feature branch on top of your master... so rebasing your feature branch to updated master and then rebase your changes from the branch on top of your master branch, then push.

In commands this will be like this:

  1. git pull (on branch master)
  2. git checkout -b feature_branch (code along here)
  3. git checkout master && git pull
  4. git checkout feature_branch && rebase master
  5. git checkout master && rebase feature_branch
  6. git push

At work I mostly encourage my coworkersto read this article on rebasing and the follow ups on the topic

Altri suggerimenti

In IntelliJ, I use the workflow as it :

  1. make sure local master is up to date
  2. create a feature branch and hack stuff
  3. In the branch, select rebase from the git menu. Onto should be your local master (refs/heads/master). Make sure "Interactive" is selected.
  4. Leave the first commit as pick or edit. Other commits would be "squash". Then start rebasing.

After a while, your branch will be rebased in your local master. You'll just have to push everything and delete your branch. If someone as pushed something to master, just let IDEA do the rebase for you.

Hope it helps

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top