git把我本地文件传到我的指定的仓库

在使用Git将本地文件推送到指定仓库之前,请确保已经安装了Git并进行了基本配置。接下来,遵循以下步骤将本地文件推送到远程仓库:
 兄弟先赏析悦目一下,摸个鱼

  1. 首先,在本地文件夹中打开命令行界面(在Windows上是命令提示符或PowerShell,而在Mac和Linux上是终端)。

  2. 初始化本地文件夹作为Git仓库:

    git init
    
  3. 添加所有文件到新建的本地仓库:
git add .

这里的 . 表示添加所有文件,如果只需添加特定文件,可以使用 git add <filename>

        4.提交文件到本地仓库:

git commit -m "Initial commit"

双引号内的文字可以替换为你的提交信息,例如 "First commit"。

        5.将本地仓库与远程仓库关联。将 your-remote-repository-url 替换为你的远程仓库URL:

git remote add origin your-remote-repository-url

例如,如果使用的是GitHub,远程仓库URL可能类似于:https://github.com/your-username/your-repository.git

        6.检查远程仓库是否添加成功:

git remote -v

 此命令将显示已关联的远程仓库。

        7.将本地文件推送到远程仓库:

git push -u origin master

此命令将本地master分支推送到远程仓库origin-u 参数表示将本地分支与远程分支进行跟踪。

完成以上步骤后,本地文件将被推送到指定的远程仓库。如果在推送过程中遇到问题,请检查你是否拥有远程仓库的写入权限。

出现以下问题

Author identity unknown *** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'Administrator@mc.(none)')

这个错误表明Git尚未配置你的用户名和邮箱,这些信息在每次提交时都会与提交一起记录。你需要设置全局或仅在此仓库中的用户名和邮箱。

按照以下步骤设置全局用户名和邮箱:

  1. 打开命令行界面。

  2. 输入以下命令以设置全局用户名:

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

将 "Your Name" 替换为你的名字。

  1. 输入以下命令以设置全局邮箱:
git config --global user.email "[email protected]"

将 "[email protected]" 替换为你的邮箱地址。

如果你只想为当前仓库设置用户名和邮箱,可以省略 --global 参数:

  1. 在当前仓库的命令行界面中输入以下命令以设置用户名:
git config user.name "Your Name"

将 "Your Name" 替换为你的名字。

  1. 输入以下命令以设置邮箱:
git config user.email "[email protected]"

将 "[email protected]" 替换为你的邮箱地址。

完成以上步骤后,再次尝试提交(git commit)并推送(git push)到远程仓库,此时错误应该已经解决。

猜你喜欢

转载自blog.csdn.net/weixin_39842528/article/details/130466328
今日推荐