该-u
选项设置存储库中的默认值以跟踪my_new_branch
. origin
因此,默认情况下,push
和都pull
将使用origin
和my_new_branch
。此后,您无需提供这些参数。这是一个例子:
$ mkdir foo; cd foo; git init; touch README; git add README; git commit -m 'README'
Initialized empty Git repository in /private/tmp/foo/.git/
[master (root-commit) 03f3d46] README
0 files changed
create mode 100644 README
$ cd ..; git clone foo bar; cd bar
Cloning into 'bar'...
done.
$ git checkout -b my-br
Switched to a new branch 'my-br'
$ touch INSTALL; git add INSTALL; git commit -m 'INSTALL'
[my-br 627d6db] INSTALL
0 files changed
create mode 100644 INSTALL
$ git push -u origin my-br
Counting objects: 3, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 245 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /tmp/foo
* [new branch] my-br -> my-br
Branch my-br set up to track remote branch my-br from origin.
$ touch Makefile; git add Makefile; git commit -m 'Makefile'
[my-br f2390c1] Makefile
0 files changed
create mode 100644 Makefile
$ git push
Counting objects: 3, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 255 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /tmp/foo
627d6db..f2390c1 my-br -> my-br
请注意,最终git push
使用正确的默认值。 主远程存储库不会被您的存储库破坏。