单一操作获取最新的 master 分支并合并到我的功能分支?

Single operation to get latest on the master branch and merge to my feature branch?

很多时候,我只是想确保在开始一天的编码之前我已经合并了最新的代码。这些步骤通常包括:

  1. 在我当前的 dev/feature 分支上存储和撤消我的更改
  2. 检查主分支
  3. 获取master上的最新代码
  4. 切换回我的分支
  5. 从 master 合并到我的分支

我在每天编写代码之前这样做,以避免在我最终必须合并到 master 时发生冲突。有没有简单的一键操作可以节省时间?

我发现这个叫做re-basing.

来自您的功能分支:

git stash
git fetch
git merge origin/master
git stash pop

或者使用别名更方便:

git config --global alias.up '!git stash && git fetch && git merge origin/master && git stash pop'

# then each time you need it, from your feature branch :

git up

很简单。了解 git 变基。 URL