gpt4 book ai didi

linux - 在 git init 上自动添加 Remote

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:26:46 25 4
gpt4 key购买 nike

有没有办法在 git init 之后自动设置 git 仓库中的 Remote ?
我知道我可以有一个 git/config 模板,但我需要一种方法来引用新的 repo 名称/目录来设置远程。

例子:

cd newProject
git init

.git/config 已经有:

[remote "origin"]
url = git@myserver:newProject
fetch = +refs/heads/*:refs/remotes/origin/*

在文件末尾。

我想我可以通过创建一个 bash 脚本来执行 git init 然后附加到配置文件,然后运行该文件而不是使用 git init ,但我希望有一种方法可以将其作为 git init 命令的一部分。

最佳答案

您可以在~/.gitconfig 中创建一个别名。例如,要使用当前目录的基本名称作为项目名称在 example.com 上创建远程:

myinit = ! "git init; git remote add origin \"git@example.com:${PWD##*/}.git\""

如果您的项目名为“foo”,当您在/path/to/foo 中运行 git myinit 时,它将初始化存储库并将 origin 设置为“git@example.com:foo.git”给你。

关于linux - 在 git init 上自动添加 Remote ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11035760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com