gitee代码上传教程(含分支)

时间:2025-05-12 19:28:56

1、gitee代码上传

1.在项目内空白处右键Git Bash Here,配置用户名和邮箱

  1. git config --global "xxx"
  2. git config --global "xxx"
  3. #检查用户名和邮箱指令
  4. git config
  5. git config

2.命令行输入下列命令,初始化本地仓库

git init

3.添加项目目录下所有文件至本地仓库

git add .

4.使用如下命令加入注释提交(说明信息为必填项,便于后期理解,此步骤必不可少!)

 git commit -m '本次提交的说明'

5.将本地仓库与远程仓库相连接

git remote add origin xxx

6.将本地仓库中的文件推送至指定的远程仓库中

git push -u origin master

如果出错error: failed to push some refs to ‘xxx“

  1. 出现错误的主要原因是gitee(github)中的README.md文件不在本地代码目录中 
  2. 此时我们要执行git pull --rebase origin master命令README.md拉到本地,
  3. 任何然后执行git push origin master

2、gitee分支代码上传

1.在项目内空白处右键Git Bash Here,配置用户名和邮箱

  1. git config --global "xxx"
  2. git config --global "xxx"
  3. #检查用户名和邮箱指令
  4. git config
  5. git config

2.命令行输入下列命令,初始化本地仓库

git init

3.添加项目目录下所有文件至本地仓库

git add .

4.使用如下命令加入注释提交(说明信息为必填项,便于后期理解,此步骤必不可少!)

 git commit -m '本次提交的说明'

5.查看所有分支 (看看是否连接上远程的git)

git branch -a

6.创建分支(xxx为你的分支起名字)

git branch xxx

7.切换分支(切换到你创建的分支,xxx为你要切换分支的名字)

git checkout xxx

8.提交代码到指定的分支 (xxx为要提交代码的分支名称)

git push origin xxx

输入git push -u origin xxx命令后出现如下错误提示:

  1. fatal: 'origin' does not appear to be a git repository
  2. fatal: Could not read from remote repository.
  3. Please make sure you have the correct access rights
  4. and the repository exists.

出现原因: 不存在origin远程仓库

解决方法: 重新关联远程仓库(xxx是远程库地址)

git remote add origin xxx
  1. #出现问题:
  2. fatal: 远程 origin 已经存在
  3. 解决:
  4. #删除远程配置
  5. git remote rm origin
  6. #重新添加
  7. git remote add origin xxx
  8. #再上传一下代码(xxx是分支名称)
  9. git push origin xxx