如何从URL中确定git remote的“名称”?

时间:2014-01-26 16:07:56

标签: git shell version-control grep repository

想象一下带有几个遥控器的克隆回购......

origin      https://github.com/mralexgray/HTTPKit (fetch)
origin      https://github.com/mralexgray/HTTPKit (push)
upstream    https://github.com/maintainer/HTTPKit (fetch)
upstream    https://github.com/maintainer/HTTPKit (push)
someguy     https://github.com/joeFschmoe/HTTPKit (fetch)
someguy     https://github.com/joeFschmoe/HTTPKit (push)

我想自动执行“重命名遥控器等”的“某些操作”。我知道URL,但不是NAMES。而不是失败已经有现有条目的重命名......

git remote rename origin upstream
fatal: remote upstream already exists.

我怎样才能“查看”已检出遥控器的现有“名称”..而不是诉诸于 grepping

git remote --localname https://github.com/joeFschmoe/HTTPKit
-> someguy

4 个答案:

答案 0 :(得分:0)

你可以从:

开始
  • 重命名远程(git remote

    git remote rename origin upstream
    fatal: remote upstream already exists.
    
  • 如果失败(状态$? != 0),请设置已存在的遥控器的网址:

    git remote set-url upstream $(git config --get remote.origin.url)
    git remote set-url origin /another/url
    

答案 1 :(得分:0)

由于遥控器的名称位于输出的最左侧,因此您可以非常简单地从grep的行中删除它(不会感到容易出错)。

我使用:

individual_dets = individual_dets %>% 
  group_by(month) %>%
  mutate(ave_temp = 
           if_else(month == "Jan" && year == 2016 , 6.529222,
            if_else (month == "Feb" && year == 2016, 6.435445,
            if_else(month == "Mar" && year == 2016, 6.505259,
            if_else(month == "Apr" && year == 2016, 6.525603,
             if_else (month == "May" && year == 2016, 6.425552,
             if_else (month == "Jun" && year == 2016, 6.488962,
             if_else (month == "Jul" && year == 2016, 6.490498,
             if_else (month == "Aug" && year == 2016, 6.417815,
             if_else (month == "Sep" && year == 2016, 6.492893,
             if_else (month == "Oct" && year == 2016, 6.502256,
             if_else (month == "Nov" && year == 2016, 6.427294,
             if_else (month == "Dec" && year == 2016, 6.508574,

            if_else(month == "Jan" && year == 2017 , 5.720514,
            if_else (month == "Feb" && year == 2017, 5.817282,
            if_else(month == "Mar" && year == 2017, 5.852279,
            if_else(month == "Apr" && year == 2017, 5.769720,
            if_else (month == "May" && year == 2017, 5.855167,
            if_else (month == "Jun" && year == 2017, 5.871033,
            if_else (month == "Jul" && year == 2017, 5.740993,
            if_else (month == "Aug" && year == 2017, 5.786351,
            if_else (month == "Sep" && year == 2017, 5.790529,
            if_else (month == "Oct" && year == 2017, 5.683220,
            if_else (month == "Nov" && year == 2017, 5.762235,
            if_else (month == "Dec" && year == 2017, 5.778975, 

             if_else(month == "Jan" && year == 2018 , 5.786351,
             if_else (month == "Feb" && year == 2018, 5.790529,
             if_else(month == "Mar" && year == 2018, 5.683220,
             if_else(month == "Apr" && year == 2018, 5.762235,
             if_else (month == "May" && year == 2018, 5.778975,
             if_else (month == "Jun" && year == 2018, 5.720514,
             if_else (month == "Jul" && year == 2018, 5.817282,
             if_else (month == "Aug" && year == 2018, 5.852279,
             if_else (month == "Sep" && year == 2018, 5.769720,
             if_else (month == "Oct" && year == 2018, 5.855167,
             if_else (month == "Nov" && year == 2018, 5.871033,
             if_else (month == "Dec" && year == 2018, 5.740993, 0
              ))))))))))))
            )))))))))))))
             ))))))))))))

其中ACCOUNT是帐户名(在GitHub上),而TYPE是“提取”或“推送”

答案 2 :(得分:0)

鉴于我们已经有了远程URL的新名称。如果有帮助,如果远程名称和URL已经存在,则以下命令不会失败。

git remote set-url --add <name> <url>

远程数据:

Name1 URL1
Name2 URL2

运行:

git remote set-url --add Name3 URL1
git remote set-url --add Name1 URL1

新的远程数据:

Name1 URL1
Name2 URL2
Name3 URL1

答案 3 :(得分:-3)

好的,所以评论者羞辱我研究它,我自己(呃,头和awk ,哈哈)我现在不知道为什么他们不仅仅是回答而不是这个花生画廊 - 废话......但是..

git remote -v | grep $URL | head -n1 | awk '{print $1}'

似乎可以解决问题。多谢你们!不

相关问题