git命令--上传到gitee

发布时间 2023-12-05 13:13:48作者: 1940

全局配置

  1. 全局配置(用Git Bash)
    git config --global user.name "账号"
    git config --global user.email "邮箱"

SSH密钥

  1. 新建密钥(用Git Bash)
    ssh-keygen -t rsa -C "邮箱名"
    按三次回车

  2. 查看密钥
    ls ~/.ssh/
    id_rsa id_rsa.pub //输出

  3. 查看密钥详情
    cat ~/.ssh/id_rsa.pub

  4. 复制id_rsa.pub,粘贴到gitee的SSH 公钥中


连接

  1. 初始化
    git init

  2. 与远程仓库连接
    git remote add origin https://gitee.com/xxx.git

  3. 代码合并(因为gitee中的README.md文件不在本地代码目录中)
    git pull --rebase origin master

  4. 所有文件添加到缓存
    git add .

  5. 将缓存区内容添加到仓库
    git commit -m "这是注释"

    若想跳过add,就执行
    git commit -am "这是注释"

  6. 取消已缓存的内容
    git reset HEAD a.txt

  7. pull服务器的代码到本地
    git pull origin master

  8. push代码到服务器
    git push origin master


其他命令

  1. 回退代码
    git reset --hard 版本号

  2. 强制推送到远程仓库
    git push -f origin develop

  3. 查看分支
    git branch

  4. 切换分支
    git checkout xxx

  5. 克隆项目库
    git clone 项目ssh地址