2012-02-11 5 views
3

は私がmaster枝にあったと新しいブランチを作成したとしますGit:作業ブランチをマスターにマージする最も速い方法は何ですか?

git checkout -b feature_branch 

私はfeature_branch上で動作するように始めた、といくつかの点で私はリベース使用masterに私の変更をマージしたいと思います。だから、私は:

# Get the latest code on master 
git checkout master 
git pull 

# Rebase on master and push the most updated 'feature_branch' 
git checkout feature_branch 
git rebase master 
git push 

# Merge 'feature_branch' to 'master' and push the updated 'master' 
git checkout master 
git merge feature_branch 
git push 

# Back to work on 'feature_branch' 
git checkout feature_branch 

ステップ数を減らし、同じを達成する方法はありますか?

プロセスの最後に、同じコミットを指すように、master,origin/masterfeature_branch、およびorigin/feature_branchとしたいと思います。

答えて

2

いくつかのコマンドを削除できます。これは、同じことを行います。

# you have to have the branch checked out to pull, since pulling means merging 
# into master, and you need a work tree to merge in 
git checkout master 
git pull 

# no need to check out first; rebase does the right thing with two arguments 
git rebase master feature_branch 

git checkout master 
git merge feature_branch 

# git push by default pushes all branches that exist here and on the remote 
git push 

git checkout feature_branch 

それが実際に作業ツリーを必要としませんが、構築されたが、実際にそこではないですので、厳密には、マスターへのマージが早送り(些細なマージ)であることが保証され、話しますチェックアウトをスキップします。回避策があります。 git push . feature_branch:master(安全だが変わっている)またはref:git update-ref master feature_branch(安全でない - 早送りかどうかをチェックしない)を直接更新するが、一般的にはブランチを素早く切り替えることもできる。

フィーチャブランチをリベースする必要がない場合は、フィーチャブランチをスキップし、feature_branchをリライトしないで、リベースされたfeature_branchおよびfast-forwardマージの代わりにmasterでマージコミットを終了することもできます。

+0

ニースの回答!スタイルのものですが、おそらく "git merge feature_branch"ではなく "git pull。feature_branch"です。また、git pushを追加するとクールになるかもしれません - タグ –

+1

@AdrianCornish: 'git pull。 feature_branch'は 'git merge feature_branch'とまったく同じことを行いますが、もっと混乱してしまいます。タグを扱う必要があることを示すためにここには何も表示されません。 – Cascabel

+0

同意する - タグが追加機能だったかもしれない:-)。 2つのコマンドが同じであることに同意します。なぜなら私は、プルリクエストワークフローが多くのOpenSourceのもので使用されていることを提案したからです。実際にあなたが書いたプルリクエストに応答しています。純粋に心の状態です - リポジトリYの著者Xが支店Zに変更を引き出しています。 –

関連する問題