github.com使用

1、下载安装git。 

2、git的初始设置 

git config --global user.name "Your Real Name" 

git config --global user.email you@email.address 

3、建立仓库 

在git bash里找到你的项目目录。(或直接用shell右键里的git bash here) 

git init 
这样在你的项目目录下就会有一个.git的隐藏目录(类似于.svn) 。 

4、初始化项目 

git add . 
留心后面的一个 "."  , 这是添加所有文件的情况,如果愿意,你也可以添加特定的几个文件,比如git add readme.txt等等。 

之后就可以做我们的first commit到仓库里了。 

git commit -m 'first commit' 
-m 参数以及后面的字串是添加说明。 

5、 注册github账号 

下面就是与github有关的操作了。 

首先到http://github.com/注册账号。注册之后可以看到这样的界面。选择第一项创建一个项目。 


6、创建SSH密匙 

这步工作应该是最麻烦的吧。回到桌面,打开git bash,输入以下命令。 

ssh-keygen -C 'your@email.address' -t rsa 
确认使用默认路径,然后输入两次你要是用的密码就行。 

可以使用以下命令测试连接(测试应该将密钥提交到github.com在测试,否则会提示无权先操作) 

SSH -v git@github.com 
会要求输入你刚才设置的密码,如果成功的话可以看到这样的ERROR(orz,起码证明连接是成功了) 

ERROR: Hi Arthraim! You've successfully authenticated, but GitHub does not provide shell access 

7、提交密匙 

现在又要回到github的页面上,在右上方工具栏里找到Account Settings。在这个页面上有一个SSH Public Keys标签,选择Add another public key。Title随便取,Key是一段东西。 

找到刚才创建密匙的那个目录下(用户根目录下的.ssh文件夹)找到id_rsa.pub文件,把它打开可以看到一堆文字,拷贝下来黏贴到github页面key的空白处。然后Apply,就好了。 

8、上传代码 

最后就是上传你的代码了~ bash切换到你的项目目录下,输入以下命令。 


git remote add origin git@github.com:你的github用户名/你的github项目名.git 

git push origin master 

hehe,现在再去“http://github.com/你的github用户名/你的github项目homepage Url” 就可以看到项目了 


附: 
你已经设置了正确的 Git URL 替换规则,但输出显示: ```bash git config --get-regexp url ``` 结果中: - ✅ 有 `url.https://github.com/.insteadOf ssh://git@github.com/` - ✅ 有 `url.https://gitclone.com/github.com/.insteadOf https://github.com/` - ❌ **没有看到 `git@github.com:` 的替换规则** 而且你还保留了多个冲突的镜像配置(`ghproxy.com`, `kgithub.com`),这会导致行为不确定。 --- ## 🔍 核心问题:**缺少对 `git@github.com:` 的转换规则** 你的项目依赖很可能写成: ```json "dom-to-image": "git+ssh://git@github.com/dmapper/dom-to-image.git" ``` 或简写为: ```json "git@github.com:dmapper/dom-to-image.git" ``` 而你只设置了: - `ssh://git@github.com/` → HTTPS ✅ - 却没设置 `git@github.com:` → HTTPS ❌ 所以当 npm 遇到 `git@github.com:...` 这种格式时,不会触发任何替换! --- ## ✅ 正确修复步骤(立即执行) ### 🧹 Step 1: 清理所有旧的、冲突的 Git 替换规则 ```bash # 删除所有与 github.com 相关的 insteadOf 规则 git config --global --unset-all url."https://github.com/".insteadof git config --global --unset-all url."https://gitclone.com/github.com/".insteadof git config --global --unset-all url."https://ghproxy.com/https://github.com/".insteadof git config --global --unset-all url."https://kgithub.com/".insteadOf git config --global --unset-all url."https://.insteadof" ``` > ⚠️ 注意:有些规则用了 `.insteadOf`(小写 o),有些是 `.InsteadOf`(大写 O)——Git 不区分大小写,但最好统一清理。 --- ### ✅ Step 2: 设置完整且有序的替换规则(关键!顺序不能错) ```bash # 1. 所有 git@github.com:user/repo → https://github.com/user/repo git config --global url."https://github.com/".insteadOf "git@github.com:" # 2. 所有 ssh://git@github.com/... → https://github.com/... git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" # 3. 所有 https://github.com/... → 国内镜像 git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/" ``` 📌 顺序很重要!必须先转 SSHgit@ → HTTPS,再转 HTTPS → 镜像。 --- ### ✅ Step 3: 验证最终规则是否正确 ```bash git config --get-regexp url ``` 你应该看到: ``` url.https://github.com/.insteadof git@github.com: url.https://github.com/.insteadof ssh://git@github.com/ url.https://gitclone.com/github.com/.insteadof https://github.com/ ``` ✅ 只有这三条,干净清晰。 --- ### ✅ Step 4: 测试替换是否生效 #### 模拟 npm 行为:测试能否通过镜像访问 ```bash git ls-remote https://github.com/dmapper/dom-to-image.git ``` 这个命令会自动被重写为: ``` https://gitclone.com/github.com/dmapper/dom-to-image.git ``` 👉 如果返回 commit 列表(不报错),说明 **替换成功!** --- ### ✅ Step 5: 清理缓存并重新安装 ```bash # 清除 npm 内部缓存的 git 克隆记录 rm -rf /home/gapinyc/.npm/_cacache/tmp/git-clone* # 删除项目依赖 rm -rf node_modules package-lock.json # 确保使用国内 npm 镜像 npm config set registry https://registry.npmmirror.com # 安装 npm install ``` --- ## 🛠️ 进阶技巧:如何确认某个 Git URL 是否被正确重写? 你可以用一个“空仓库”来测试地址解析: ```bash git clone https://github.com/dmapper/dom-to-image.git test-dom-to-image --depth=1 ``` 如果成功克隆,并且实际是从 `gitclone.com` 下载的,说明一切正常。 查看详细请求过程(可选): ```bash GIT_CURL_VERBOSE=1 git ls-remote https://github.com/dmapper/dom-to-image.git ``` 你会在输出中看到: ``` About to connect() to gitclone.com port 443 ``` 🎯 表示流量已走镜像! --- ## ✅ 推荐终极方案(再次强调):Yarn + resolutions 即使你现在能修好 Git,**强烈建议切换到 Yarn 方案**,因为: - Git 依赖不稳定(网络、权限、协议) - 构建速度慢 - CI/CD 易失败 ### 使用 `dom-to-image-more` 替代 修改 `superset-frontend/package.json`: ```json { "dependencies": { "dom-to-image-more": "^3.2.0" }, "resolutions": { "dom-to-image": "npm:dom-to-image-more@^3.2.0" } } ``` 然后: ```bash npm install -g yarn yarn config set registry https://registry.npmmirror.com rm -rf node_modules package-lock.json yarn install ``` ✅ 成功绕开所有 Git 问题! --- ## ✅ 总结:你现在要做的就是 ```bash # 1. 彻底清理旧规则 git config --global --unset-all url."https://github.com/".insteadof git config --global --unset-all url."https://gitclone.com/github.com/".insteadOf # (其他类似) # 2. 设置三步替换规则(顺序不能错) git config --global url."https://github.com/".insteadOf "git@github.com:" git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/" # 3. 验证 git config --get-regexp url # 4. 测试 git ls-remote https://github.com/dmapper/dom-to-image.git # 5. 清理并安装 rm -rf /home/gapinyc/.npm/_cacache/tmp/git-clone* node_modules package-lock.json npm config set registry https://registry.npmmirror.com npm install ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值