我有两个分支,即master与development在GitHub的库.我正在开发分支中进行所有开发,如图所示.
git branch development
git add *
git commit -m "My initial commit message"
git push -u origin development
Run Code Online (Sandbox Code Playgroud)
现在我想将development分支上的所有更改合并到master.我目前的做法是:
git checkout master
git merge development
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
如果我遵循的程序是正确的,请告诉我.
Sai*_*esh 1082
我通常喜欢合并master到第development一个,所以如果有任何冲突,我可以解决development分支本身和我的master遗骸.
(on branch development)$ git merge master
(resolve any merge conflicts if there are any)
git checkout master
git merge development (there won't be any conflicts now)
Run Code Online (Sandbox Code Playgroud)
这两种方法没有太大区别,但我注意到有时我不想在合并之后将分支master合并到一起,或者在合并它们之前还有更多的工作要做.所以我倾向于master保持不变,直到最后的东西.
编辑:来自评论
如果你想跟踪谁做了合并以及何时合并,你可以在合并时使用--no-ffflag来这样做.这是合并只有当一般有用development到master(最后一步),因为你可能需要合并master到development工作流程中的多次(第一步),并创建一个提交节点,这些可能不是非常有用的.
git merge --no-ff development
Run Code Online (Sandbox Code Playgroud)
Dav*_*ulp 94
就个人而言,我的方法与你的方法相似,只需要更多的分支,并且当他们回到主人的时候会有一些压缩的提交.
我的一个同事不喜欢不得不这么多地切换分支并且保持在开发分支上,所有类似于以下内容都是从开发分支执行的.
git fetch origin master
git merge master
git push origin development:master
Run Code Online (Sandbox Code Playgroud)
第一行确保自上次更新本地存储库以来,他已经进行了任何上游提交.
第二个将这些更改(如果有的话)从master转移到开发中
第三个将开发分支(现在与master完全合并)推送到origin/master.
我的基本工作流程可能有点不对劲,但这是它的主要要点.
Ged*_*nas 24
对于那些来到这里而不了解分支的人来说,从底部解释.
基本主分支开发逻辑是:您只在另一个分支上工作,并仅使用master来合并另一个分支.
您开始以这种方式创建一个新分支:
1)在您的Web根目录中克隆所需的存储库:
$ cd /var/www
$ git clone git@bitbucket.org:user_name/repository_name.git
Run Code Online (Sandbox Code Playgroud)
2)创建一个新分支.它将包含主分支存储库的最新文件
$ git branch new_branch
Run Code Online (Sandbox Code Playgroud)
3)将git branch更改为new_branch
$ git checkout new_branch
Run Code Online (Sandbox Code Playgroud)
4)像往常一样编码,提交......
$ git add .
$ git commit -m “Initial commit”
$ git push (pushes commits only to “new_branch”)
Run Code Online (Sandbox Code Playgroud)
5)当在该分支上完成作业时,与"master"分支合并:
$ git merge master
$ git checkout master (goes to master branch)
$ git merge development (merges files in localhost. Master shouldn’t have any commits ahead, otherwise there will be a need for pull and merging code by hands!)
$ git push (pushes all “new_branch” commits to both branches - “master” and “new_branch”)
Run Code Online (Sandbox Code Playgroud)
Har*_*sha 21
如果你可以使用Git Flow工作流程会很棒.它可以轻松地将开发分支合并到master中.
你想要做的只是按照这里提到的git flow指令:
http://danielkummer.github.io/git-flow-cheatsheet/
脚步:
请查看以上链接以获取更多信息.
如果您使用Mac或Ubuntu,请转到分支的工作文件夹。在终端
假设harisdev是分支名称。
git checkout master
Run Code Online (Sandbox Code Playgroud)
如果存在未跟踪或未提交的文件,则会出现错误,并且必须提交或删除所有未跟踪或未提交的文件。
git merge harisdev
git push origin master
Run Code Online (Sandbox Code Playgroud)
最后一个删除分支的命令。
$ git branch -d harisdev
Run Code Online (Sandbox Code Playgroud)
步骤1
创建并切换到新的“ dev”分支,在该分支中,本地git文件与远程数据库同步,但“ dev”分支尚不存在。
git branch dev # create
git checkout dev # switch
# No need to git add or git commit, the current
# branch's files will be cloned to the new branch by-default.
git push --set-upstream origin dev # push the "dev" branch to the remote.
Run Code Online (Sandbox Code Playgroud)
第2步
对“ dev”分支进行更改(如果遵循步骤1,则为当前更改),提交并将其推送到远程“ dev”分支。
git add .
git commit -S -m "my first commit to the dev branch" # remove the -S if you're not "secure", secure = when you already setup crypto private and public keys (i.e "verified" green sign in github)
git push -u origin dev # push the changes to the remote, -u origin dev is optional but good to use.
Run Code Online (Sandbox Code Playgroud)
第三步
将您的“ dev”分支合并到“ master”中。
git checkout dev # switch to "dev" branch if you're not already.
git merge master # optionally, this command is being used to resolve any conflicts if you pushed any changes to your "master" but "dev" doesn't have that commit.
git checkout master # switch to "master", which is the branch you want to be merged.
git merge --no-ff dev # merge the "dev" branch into the "master" one.
Run Code Online (Sandbox Code Playgroud)