【问题标题】:Push all locally non tracked branches to the same remote将所有本地未跟踪的分支推送到同一个远程
【发布时间】:2022-01-04 17:23:09
【问题描述】:

我的电脑上有多个本地分支,没有远程。

我想将所有未跟踪远程的本地分支(我有多个远程,例如 originupstream)推送到同一个远程(例如备份)url。用于备份目的。

我该怎么做?

解决方案可以是直接 Git 命令或 bash 脚本,用于列出没有远程的分支(我有多个远程名称)并遍历它们以将它们推送到同一个远程。

【问题讨论】:

  • 呃,对于每个有问题的分支,你会说git push <myremote> <mybranch>。例如,git push origin branch1。你能解释一下困难是什么吗?
  • @matt 我认为他们正在寻找能够推送所有这些的东西,即无需手动输入每个分支名称。
  • @matt 没错,我有很多未跟踪的分支(例如用于调试目的或未完成的功能),我想将它们全部推送用于备份目的。跨度>
  • 可能我的问题更适合 bash 脚本。列出所有没有远程 (stackoverflow.com/a/31776247) 的本地分支 + 迭代它们的组合。不幸的是,我对 bash 脚本的了解很差。
  • 你试过git push --all -u吗?

标签: bash git


【解决方案1】:

可能我的问题更适合 bash 脚本。
listing all local branches without remote + 对它们进行迭代的组合。

#!/bin/bash
while IFS= read -r aBranch ; do {  
  echo "Push ${aBranch} to backup";  
  git push backup "${aBranch}"
};
done < <(git branch --format '%(refname:short) %(upstream:short)' | awk '{if (!$2) print $1;}');
unset aBranch ;

【讨论】:

  • 相当整洁。我认为您在这里不需要IFSwhile read branch; do ... done &lt; &lt;(git branch --format '%(refname:short) %(upstream:short)'...) 更简单
猜你喜欢
  • 2016-02-22
  • 2018-02-12
  • 1970-01-01
  • 2013-04-30
  • 2010-09-27
  • 2014-02-04
  • 2011-07-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多