简体   繁体   中英

git branch workflow

I'm wondering what the proper workflow for branches are and pulling from master.

I've created a branch and I have files with modifications to them. In the master I've done some bug fixes which I need in my branch. When I try to pull my IDE warns me that the changes in my branch will be overwritten and that I should commit first, however I'm not at a point where I should commit.

What's the proper workflow for branches with modifications that I need to pull from master?

If you would like to pull changes in to a "dirty" tree you can simply git stash and complete your git merge ... . Once that's done you can restore your changes with git stash pop .

I would like to clarify few things:

  1. First "pull" in git terminology is only applicable when you are merging changes from remote branch to your local branch, but not between your local branches. In case of local branches it will be merge or rebase.

  2. if you are having a master branch with some bugfixes and some dev branch in which (I'm talking local branches now) you are developing some new feature, then it seems that master branch is an upstream for your dev branch. Therefore in order to preserve the history as a straight line in your dev branch and also to have a fast-forward merge of your dev branch into the master branch in future i would recommend to use rebase instead of merge.

Ie instead of:

git checkout dev
git merge master

You would do

git checkout dev
git rebase (-i) master

Argument "-i" is optional - triggers interactive rebase. Of course this should be also executed on clean working directory. The point is though that with git you don't have to keep working directory dirty for long time, don't have to accumulate changes. You can easily commit your changes as small single purposed units to your local branches and then clean them'up later on using interactive rebase

from git rebase docs :

Assume the following history exists and the current branch is "topic":

  A---B---C topic / D---E---F---G master 

From this point, the result of either of the following commands:

 git rebase master git rebase master topic 

would be:

  A'--B'--C' topic / D---E---F---G master 

NOTE: The latter form is just a short-hand of git checkout topic followed by git rebase master. When rebase exits topic will remain the checked-out branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM