• [git]上传代码到github


    这里主要分为两种情况,一种是我们自己创建的代码上传,另一种是我们先clone别的代码修改后上传(这种情况更常见)

    注意!前提是需要自己注册好github账号,同时与本机的ssh也已经配置完成(具体配置方法见文章)

    一、账号准备工作

    1、github网站
    登录https://github.com/注册github账号

    2、本地用户配置
    注册登录好后打开终端,在本地上进行操作

    git config --global user.name "github's Name"
    git config --global user.email "github@xx.com"
    git config --list
    
    • 1
    • 2
    • 3

    如果想要某一个项目的账户与全局账户不同,在当前项目下面设置全局配置+当前项目的配置, 使用的时候会优先使用当前项目的配置

    git config user.name "gitlab's Name"
    git config user.email "gitlab@xx.com"
    git config --list
    
    • 1
    • 2
    • 3

    分别查看状态:

    git config user.name
    git config user.email
    
    • 1
    • 2

    3、ssh配置
    检查本地有没有ssh配置,如果有直接复制

    cd ~/.ssh
    ls
    
    • 1
    • 2

    如果没有,生成ssh文件:

    ssh-keygen -t rsa -C "xxx@xxx.com"
    
    • 1

    复制ssh内容

    cd ~/.ssh
    cat id_rsa.pub
    
    • 1
    • 2

    github网页上添加,点击右上角图像->Settings->左侧SSH and GPG keys->右上角New ssh keys->将内容复制到Key框图里面

    验证是否设置成功:

    ssh -T git@github.com
    
    • 1

    二、针对于自己创建代码,就和网上教程相同

    1、github网址上设置仓库
    直接点New repository创建仓库

    2、本地处理
    新建文件夹,编写程序

    git init
    git add .
    git commit -m "name"
    
    • 1
    • 2
    • 3

    3、将本地git仓库与远程联系起来

    git remote add origin https://github.com/账户名/git仓库
    
    • 1

    4、上传代码

    git push -u origin master
    git push -u origin main
    
    • 1
    • 2

    三、针对于网上clone下的代码

    1、github网址上设置仓库
    直接点New repository创建仓库

    2、本地处理

    git clone ***
    做一些修改
    git add .
    git commit -m "name"
    
    • 1
    • 2
    • 3
    • 4

    3、将本地git仓库与远程联系起来

    git remote add origin https://github.com/账户名/git仓库
    
    • 1

    注意!这里如果报错 fatal: remote origin already exists.

    git remote rm origin
    git remote add origin https://github.com/账户名/git仓库
    
    • 1
    • 2

    4、上传代码

    git push -u origin master
    
    • 1

    5、other code want to pull the new branch

    git remote add origin https://github.com/账户名/git仓库
    git pull
    git checkout -b new_branch origin/new_branch
    
    • 1
    • 2
    • 3

    四、github常用代码

    git branch -a
    
    git checkout -b Quantization origin/Quantization
    切换到远程分支
    
    
    修改出现问题需要回退:
    git add .
    git checkout -b Quantization_gru(新建一个分支)
    git add .
    git commit -m "first"
    git checkout -(切换回原分支)
    
    
    
    一、常用增删命令(本地&远程)
    1、在本地新建一个分支 
    git branch newBranch
    2、切换到你本地新建的分支
    git checkout newBranch
    3、创建并切换到新建本地分支
    git checkout -b newBranch
    4、将新创建本地分支推送到远程仓库
    git push origin newBranch
    或者
    git push 远程仓库名 newBranch
    5、删除本地一个分支
    git branch -d newBranch
    6、删除远程一个分支
    git push origin :newBranch (分支名前的冒号代表删除)
    
    commit出现问题需要撤销,但是修改文件保持不变
    git reset --soft HEAD^
    撤销add
    git reset HEAD .
    
    git push origin ins-model-modify
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
  • 相关阅读:
    Vue与TypeScript的配合:如何在Vue项目中使用TypeScript,利用静态类型提高代码的可维护性
    I.MX6U-ALPHA开发板(DDR3实验)
    关于DAG的一些零散记录
    C语言学生综合测评系统
    技术分享 | orchestrator--运维--配置集群自动切换&测试
    百数服务商模式:为制造业未来插上数字化的翅膀,创造商机!
    第 367 场 LeetCode 周赛题解
    【计算机视觉40例】案例35:人脸对齐
    Orin PPS failed to request pps gpio修改
    Linux下Cmake安装或版本更新
  • 原文地址:https://blog.csdn.net/weixin_41169280/article/details/127686162