Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

git - 如何将新的本地分支推送到远程Git存储库并进行跟踪?(How do I push a new local branch to a remote Git repository and track it too?)

I want to be able to do the following:

(我希望能够做到以下几点:)

  1. Create a local branch based on some other (remote or local) branch (via git branch or git checkout -b )

    (基于其他(远程或本地)分支创建本地分支(通过git branchgit checkout -b ))

  2. Push the local branch to the remote repository (publish), but make it trackable so git pull and git push will work immediately.

    (将本地分支推送到远程存储库(发布),但使其可跟踪,以便git pullgit push立即生效。)

How do I do that?

(我怎么做?)

I know about --set-upstream in Git 1.7, but that is a post-creation action.

(我知道--set-upstream在Git 1.7中设置--set-upstream ,但这是一个创建后的动作。)

I want to find a way to make a similar change when pushing the branch to the remote repository.

(我想找到一种方法,在将分支推送到远程存储库时进行类似的更改。)

  ask by Roni Yaniv translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In Git 1.7.0 and later, you can checkout a new branch:

(在Git 1.7.0及更高版本中,您可以签出一个新分支:)

git checkout -b <branch>

Edit files, add and commit.

(编辑文件,添加和提交。)

Then push with the -u (short for --set-upstream ) option:

(然后使用-u (-- --set-upstream缩写)选项推送 :)

git push -u origin <branch>

Git will set up the tracking information during the push.

(Git将在推送期间设置跟踪信息。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...