这里主要分为两种情况,一种是我们自己创建的代码上传,另一种是我们先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
如果想要某一个项目的账户与全局账户不同,在当前项目下面设置全局配置+当前项目的配置, 使用的时候会优先使用当前项目的配置
git config user.name "gitlab's Name"
git config user.email "gitlab@xx.com"
git config --list
分别查看状态:
git config user.name
git config user.email
3、ssh配置
检查本地有没有ssh配置,如果有直接复制
cd ~/.ssh
ls
如果没有,生成ssh文件:
ssh-keygen -t rsa -C "xxx@xxx.com"
复制ssh内容
cd ~/.ssh
cat id_rsa.pub
github网页上添加,点击右上角图像->Settings->左侧SSH and GPG keys->右上角New ssh keys->将内容复制到Key框图里面
验证是否设置成功:
ssh -T git@github.com
1、github网址上设置仓库
直接点New repository创建仓库
2、本地处理
新建文件夹,编写程序
git init
git add .
git commit -m "name"
3、将本地git仓库与远程联系起来
git remote add origin https://github.com/账户名/git仓库
4、上传代码
git push -u origin master
git push -u origin main
1、github网址上设置仓库
直接点New repository创建仓库
2、本地处理
git clone ***
做一些修改
git add .
git commit -m "name"
3、将本地git仓库与远程联系起来
git remote add origin https://github.com/账户名/git仓库
注意!这里如果报错 fatal: remote origin already exists.
git remote rm origin
git remote add origin https://github.com/账户名/git仓库
4、上传代码
git push -u origin master
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
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