要连接到远程 Git 仓库,你需要在 Git Bash 中执行以下步骤:
首先,打开 Git Bash 终端窗口。
进入本地 Git 仓库所在的目录。
输入以下命令设置你的 Git 用户名和邮箱地址:
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@example.com"
在 GitHub 或 GitLab 上创建一个新的远程仓库。
复制远程仓库的 SSH 地址或 HTTPS 地址。
在 Git Bash 中输入以下命令将本地仓库关联到远程仓库:
- 如果使用 SSH 地址:
$ git remote add origin git@github.com:username/repo.git
- 如果使用 HTTPS 地址:
$ git remote add origin https://github.com/username/repo.git
- 输入以下命令验证是否成功连接到远程仓库:
$ git remote -v
如果一切顺利,你应该会看到类似下面的输出:
origin git@github.com:username/repo.git (fetch)
origin git@github.com:username/repo.git (push)
现在,你已经成功连接到远程 Git 仓库了。