我已经看过推送命令的三个版本:
git push -u remote_repo_ref local_branch_name
和
git push remote_repo_ref local_branch_name
和
git push
我有点不清楚何时使用哪一个。通常remote_repo_ref
为origin
而local_branch_name
为master
,但我在此处使用常规标签可以使我的问题更加通用。
答案 0 :(得分:1)
第一次推送到远程/上游时使用git push -u
。下面是一个示例“下方”,您需要何时使用git push -u remote_repo_ref local_branch_name
。
让我们说,我们已经检查了一些代码,我们只需要添加一个新的分支并检查它......
=>
# view current branches.
za:webapp za$ git branch
master
* paperclip_file_up_down_load_and_s3
=>
# create a new branch called some _feature
za:webapp za$ git checkout -b some_feature
M app/models/video.rb
Switched to a new branch 'some_feature' paperclip_file_up_down_load_and_s3
=>
# Check what is under .git/refs/remotes/origin/
# you can get more details suing za$ git remote show origin
# Note: branch soe_feature is not there yet
za:webapp za$ ls -lad .git/refs/remotes/origin/*
-rw-r--r-- 1 za staff 41 Nov 11 13:49 .git/refs/remotes/origin/master
-rw-r--r-- 1 za staff 41 Nov 26 14:06 .git/refs/remotes/origin/paperclip_file_up_down_load_and_s3
#Add it using git push -u origin some_feature
za:webapp za$ git push -u origin some_feature
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/codepedia/webapp.git
* [new branch] some_feature -> some_feature
Branch some_feature set up to track remote branch some_feature from origin.
=>
# Check again, it is there. Was linked remote origin via the flag -u
# You can also run git push -u origin some_feature
za:webapp za$ ls -lad .git/refs/remotes/origin/*
-rw-r--r-- 1 za staff 41 Nov 11 13:49 .git/refs/remotes/origin/master
-rw-r--r-- 1 za staff 41 Nov 26 14:06 .git/refs/remotes/origin/paperclip_file_up_down_load_and_s3
-rw-r--r-- 1 za staff 41 Jan 21 21:09 .git/refs/remotes/origin/some_feature
至于其他两个:
git push
是git push remote_repo_ref local_branch_name
git push remote_repo_ref local_branch_name
你这里只是冗长/明确。当已经签入本地主OR分支并且链接到上游时,使用git push
。
希望有所帮助!!