本文翻译自:Git - push current branch shortcut

Is there a shortcut to tell Git to push the current tracking branch to origin? 是否有快捷方式告诉Git将当前跟踪分支推送到原点?
Note: I know that I can change the default push behavior , but I am looking for an ad-hoc solution that does not change the default behavior. 注意:我知道我可以更改默认推送行为 ,但我正在寻找一种不会改变默认行为的临时解决方案。

For example, suppose I am on branch feature/123-sandbox-tests I would be using 例如,假设我正在使用分支feature/123-sandbox-tests

git push origin feature/123-sandbox-tests

which is tedious. 这很乏味。 I am looking for a shortcut, something like 我正在寻找一条捷径,比如说

git push origin current

where git knows that current is feature/123-sandbox-tests . git知道当前是feature/123-sandbox-tests


Edit : Starting from version 2.0, git's default behavior has changed to a more intuitive behavior, which is what I wanted to achieve. 编辑 :从版本2.0开始,git的默认行为已更改为更直观的行为,这是我想要实现的。 See This SO question for details. 有关详细信息,请参阅此SO问题

Edit 2 : ceztko's answer is the best answer as it allows to push the current branch, regardless of the settings. 编辑2 : ceztko的答案是最好的答案,因为它允许推送当前分支,无论设置如何。


#1楼

参考:https://stackoom.com/question/wsM6/Git-推送当前分支快捷方式


#2楼

If you are using git 1.7.x, you can run the following command to set the remote tracking branch. 如果您使用的是git 1.7.x,则可以运行以下命令来设置远程跟踪分支。

git branch --set-upstream feature/123-sandbox-tests origin/feature/123-sandbox-tests

Then you can simply use git push to push all the changes. 然后你可以简单地使用git push来推送所有的变化。 For a more complete answer, please see the accepted answer to a similar question here. 如需更完整的答案,请在此处查看类似问题的已接受答案。

If you only want to push the current branch with the push command, then you can change the push behaviour to upstream: 如果您只想使用push命令推送当前分支,则可以将推送行为更改为上游:

git config --global push.default upstream

#3楼

The simplest way: run git push -u origin feature/123-sandbox-tests once. 最简单的方法:运行git push -u origin feature/123-sandbox-tests一次。 That pushes the branch the way you're used to doing it and also sets the upstream tracking info in your local config. 这会按照您习惯的方式推送分支,并在本地配置中设置上游跟踪信息。 After that, you can just git push to push tracked branches to their upstream remote(s). 之后,您可以通过git push将跟踪的分支推送到其上游远程。

You can also do this in the config yourself by setting branch.<branch name>.merge to the remote branch name (in your case the same as the local name) and optionally, branch.<branch name>.remote to the name of the remote you want to push to (defaults to origin). 您也可以通过将branch.<branch name>.merge设置为远程分支名称(在您的情况下与本地名称相同)并可选地将branch.<branch name>.remote设置为名称来自行配置。要推送的遥控器(默认为原点)。 If you look in your config, there's most likely already one of these set for master , so you can follow that example. 如果您查看配置,很可能已经为master设置了其中一个,因此您可以按照该示例进行操作。

Finally, make sure you consider the push.default setting. 最后,请确保考虑push.default设置。 It defaults to "matching", which can have undesired and unexpected results. 它默认为“匹配”,这可能会产生意外和意外的结果。 Most people I know find "upstream" more intuitive, which pushes only the current branch. 我认识的大多数人发现“上游”更直观,只推动当前分支。

Details on each of these settings can be found in the git-config man page . 有关这些设置的详细信息,请参阅git-config手册页 。

On second thought, on re-reading your question, I think you know all this. 第二个想法,重新阅读你的问题,我想你知道这一切。 I think what you're actually looking for doesn't exist. 我认为你真正想要的东西不存在。 How about a bash function something like (untested): bash函数怎么样(未经测试):

function pushCurrent {git config push.default upstreamgit pushgit config push.default matching
}

#4楼

According to git push documentation: 根据git push文档:

git push origin HEADA handy way to push the current branch to the same name on the remote.

So I think what you need is git push origin HEAD . 所以我认为你需要的是git push origin HEAD Also it can be useful git push -u origin HEAD to set upstream tracking information in the local branch, if you haven't already pushed to the origin. 如果你还没有推到原点,那么git push -u origin HEAD可以在本地分支中设置上游跟踪信息。


#5楼

For what it's worth, the ultimate shortcut: 对于它的价值,最终的捷径:

In my .bash_profile I have alias push="git push origin HEAD" , so whenever i type push I know I'm pushing to the current branch I'm on. 在我的.bash_profile我有alias push="git push origin HEAD" ,所以无论何时我输入push我都知道我正在推送到我当前的分支。


#6楼

With the help of ceztko's answer I wrote this little helper function to make my life easier: 在ceztko的回答的帮助下,我写了这个小助手功能,让我的生活更轻松:

function gpu()
{if git rev-parse --abbrev-ref --symbolic-full-name @{u} > /dev/null 2>&1; thengit push origin HEADelsegit push -u origin HEADfi
}

It pushes the current branch to origin and also sets the remote tracking branch if it hasn't been setup yet. 它将当前分支推送到原点,并设置远程跟踪分支(如果尚未设置)。

Git - 推送当前分支快捷方式相关推荐

  1. git 推送本地分支到远程分支 git push origin

    ** 情形:**在本地分支local_branch修改了代码,之后要提交到远程分支remote_branch上,使用命令git push origin remote_branch报错. ** 报错:* ...

  2. git推送本地分支到远程分支

    场景 有时候我们开发需要开一个分支,这样可以有效的并行开发. 开分支有两种方式: 一种是在远程开好分支,本地直接拉下来; 一种是本地开好分支,推送到远程. 远程先开好分支然后拉到本地 git chec ...

  3. 【git提交代码步骤,git推送本地分支到dev】

    一.提交到本地仓库 1.创建本地分支,在本地分支上进行开发 git checkout -b mybranch 新建并切换到本地dev分支 2.提交更新 git status #查看已更改文件 git ...

  4. 功能分支重新设置后,Git推送被拒绝

    好的,我以为这是一个简单的git场景,我缺少什么? 我有一个master分支和一个feature分支. 我在master上做一些工作,在feature上做一些,然后再在master上做更多的工作. 我 ...

  5. git推送分支到远程分支

    git  push oringin branchname:branchname 推送当前分支的内容到远程分支branchname上 在push前rebase一下更好  git rebase origi ...

  6. 利用 git 提交代码、git 简单使用(拉取、推送、分支、合并)

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1.安装 git sudo apt-get install git 2.查看版本: git --ve ...

  7. 解决git rebase操作后推送远端分支不成功的问题

    解决git rebase操作后推送远端分支不成功的问题 参考文章: (1)解决git rebase操作后推送远端分支不成功的问题 (2)https://www.cnblogs.com/xinmengw ...

  8. git push 推送当前分支 与 config中的push default

    git push origin与git push -u origin master的区别 $ git push origin 上面命令表示,将当前分支推送到origin主机的对应分支. 如果当前分支只 ...

  9. git新建分支:新建本地分支并创建远程分支,推送本地分支(已有工程)

    sublime merge是个git可视化软件 背景:已有工程,需要新建一个分支push新项目 如下:本地分支为blemish等,远程分支为origin下分支. 创建之间切换到master分支,防止后 ...

最新文章

  1. 1秒极速求解PDE:深度神经网络为何在破解数学难题上独具天赋?
  2. DL之DNN:自定义2层神经网络TwoLayerNet模型(封装为层级结构)利用MNIST数据集进行训练、预测
  3. Matlab中newff函数使用方法和搭建BP神经网络的方法
  4. 如何从几何角度上理解方程组只有一个解_深度科普---电磁波(三):无激励下的真空中的Maxwell方程组的解...
  5. JS中关于clientWidth、offsetWidth、scrollWidth
  6. CCF数图焦点 | 数据治理
  7. Linux操作系统基础知识学习
  8. Nested Loop Join入门
  9. linux -- 个人笔记
  10. missing arguments for method toArray in trait Collection
  11. 自动化遍历-appcrawler
  12. python人脸识别方法_python实现人脸识别代码
  13. linux系统安装pidgin,linux 下安装pidgin-lwqq
  14. tp6后台管理系统搭建
  15. steam游戏开发_如何从Steam Cloud下载保存的游戏
  16. 微信小程序(7)说说微信小程序的发布流程?
  17. FICO凭证错误:BKPFF$PRDCLN800在FI中达到的项目最大编号
  18. 简单的复习下箭头函式
  19. 你的能力是更适合做微商还是淘宝
  20. vue设置页面的高度100%

热门文章

  1. linux下静默安装weblogic 12
  2. centos6.5 mysql5.6.24 单实例二进制包安装
  3. 关于java mail 发邮件的问题总结(转)
  4. 【php】mysql全局ID生成方案
  5. ftp 425 Can't open data connection. 的解决方案
  6. apache配置好后编译rewrite
  7. js面向对象的程序设计 --- 中篇(创建对象) 之 原型模式
  8. IOS NSNotification 通知
  9. 用闭包方式实现点击a标签弹也索引值
  10. 爬虫----Scrapy框架