何时使用git push的特定参数?
当你首次推送到远程/上游时,使用git push -u
。以下是一个使用git push -u remote_repo_ref local_branch_name
的示例,当你需要添加一个新的分支并将其提交时,你需要使用它。
假设我们已经有一些已经检入的代码,我们只需要添加一个新的分支并检入它......
=> # 查看当前分支。 za:webapp za$ git branch master * paperclip_file_up_down_load_and_s3 => # 创建一个名为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 => # 检查.git/refs/remotes/origin/下的内容。 # 你可以使用za$ git remote show 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 # 使用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. => # 再次检查,它已经存在。通过-u标志与远程origin关联。 # 你也可以运行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
是显式的写法。当本地主分支或分支已经检入并与上游关联时,你使用git push
。
希望对你有所帮助!
如果你不断使用特性分支,上游将不断变化,所以在这种情况下使用-u并不重要,我是对的吗?