以下步骤适用于我:
初始化
首先,使用 Git
初始化仓库,以便跟踪任何文件更改:
git init
然后,检查您想要与别名origin
关联的远程存储库是否存在,如果不存在,请先在git
中创建它。
$ git ls-remote https://github.com/repo-owner/repo-name.git/
如果它存在,将其与远程别名"origin"关联起来。
git remote add origin https://github.com:/repo-owner/repo-name.git
并使用 git remote -v
检查远程 别名“origin”属于哪个URL:
$ git remote -v
origin https://github.com:/repo-owner/repo-name.git (fetch)
origin https://github.com:/repo-owner/repo-name.git (push)
验证别名来源
接下来,验证您的别名origin是否已正确地进行了别名化,具体如下:
$ cat ./.git/config
:
[remote "origin"]
url = https://github.com:/repo-owner/repo-name.git
fetch = +refs/heads/*:refs/remotes/origin/*
:
你一定要看看这个部分[remote "origin"]
。你可以考虑使用GitHub Desktop,它适用于Windows和MacOS,可以帮助我自动填充~./git/config
文件中缺失的部分,或者你也可以手动添加,虽然不是很好,但它确实有效!
从远程主分支拉取任何内容
$ git pull origin main
这将从您刚刚别名为origin
的存储库中拉取任何内容到本地存储库,包括.gitignore
,并在此过程中创建分支main
。
检查主分支
$ git branch
* main
这将向你展示已经创建了main
分支,并且你现在位于它上面(由*指示)。
可选项
如果你正在使用多个origin
,你可能还想更改origin
的别名,使其更直观:
git remote rename origin my-super-git-repo
最终
git add .
git status //If you want to check what's going to be committed
git commit -m 'First commit' //-m is for message
git push origin main
你会看到如下一堆行:
列举对象:22, 已完成。
计算对象:100% (22/22), 已完成。
使用多达8个线程进行增量压缩
压缩对象:100% (13/13), 已完成。
写入对象:100% (21/21), 4.29 KiB | 292.00 KiB/s, 已完成。
总共 21 个对象(Delta 2),重复使用 0 个对象(Delta 0),包重用 0 个对象
remote: 解析 Delta:100% (2/2), 已完成。
To https://github.com/repo-owner/repo-name.git
948279c..1f3b0b8 main -> main
git remote -v
什么也没有显示。 - Vijayremote: Repository not found. fatal: repository 'https://github.com/VijayNew/NewExample.git/' not found
。 - Vijay