我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
当前回答
我假设你已经克隆了这样的项目:
git clone http://github.com/myproject.git
然后在您的本地副本中,创建一个新的分支,并检查它: git checkout -b <newbranch> 假设您在您的服务器上创建了一个“git bare --init”并创建了 myapp.git,您应该: git remote 添加起源 ssh://example.com/var/git/myapp.git git push 起源主 之后,用户应该能够 git clone http://example.com/var/git/myapp.git
注意:我假设你有你的服务器上运行,如果没有,它不会工作。
添加
添加一个远程分支:
git push origin master:new_feature_name
检查一切是否好(Fetch起源和列出远程分支):
git fetch origin
git branch -r
创建一个本地分支,并跟踪远程分支:
git checkout -tb new_feature_name origin/new_feature_name
更新一切:
git pull
其他回答
在 Git 1.7.0 或更高版本中,您可以查看一个新的分支:
git checkout -b <branch>
编辑文件,添加和承诺. 然后按下 -u (缩写为 --set-upstream) 选项:
git push -u origin <branch>
Git 在推时将设置跟踪信息。
对于 1.7 之前的 GitLab 版本,使用:
git checkout -b name_branch
(名称_branch,前:大师)
要将其推到远程存储库,请:
git push -u origin name_new_branch
(名称_new_branch,例子:属性)
我假设你已经克隆了这样的项目:
git clone http://github.com/myproject.git
然后在您的本地副本中,创建一个新的分支,并检查它: git checkout -b <newbranch> 假设您在您的服务器上创建了一个“git bare --init”并创建了 myapp.git,您应该: git remote 添加起源 ssh://example.com/var/git/myapp.git git push 起源主 之后,用户应该能够 git clone http://example.com/var/git/myapp.git
注意:我假设你有你的服务器上运行,如果没有,它不会工作。
添加
添加一个远程分支:
git push origin master:new_feature_name
检查一切是否好(Fetch起源和列出远程分支):
git fetch origin
git branch -r
创建一个本地分支,并跟踪远程分支:
git checkout -tb new_feature_name origin/new_feature_name
更新一切:
git pull
简单地说,要创建一个新的地方分支,做:
git branch <branch-name>
要将其推到远程存储库,请:
git push -u origin <branch-name>
我创建了一个标签,所以每当我创建一个新的分支,它将按下推和跟踪远程分支。
# Create a new branch, push to origin and track that remote branch
publishBranch() {
git checkout -b $1
git push -u origin $1
}
alias gcb=publishBranch
使用: 只是用 thuy/do-sth-kool 输入 gcb thuy/do-sth-kool 是我的新分支名称。