前阵子机器不稳定出现bug,所以想着用github托管代码,这里记录一下流程。
github web 操作
首先添加本地的ssh公钥,如果没有的话ssh-keygen -t rsa
一路回车,会生成在~/.ssh中。然后在github的web端添加
然后在github新建一个仓库。
本地操作
在代码目录下git init
初始化本地版本库,然后git add .
加至暂存区跟踪,git commit -m "comment"
提交至本地仓库并添加注释(这里可能需要首先添加邮箱和用户名)
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
至此,code保存至本地仓库,使用git log
查看提交历史。
#查看和切换本地分支
git branch #显示本地分支,-a/-r显示全部/远程分支
git branch <newbranch> #新建分支
git checkout #切换本地分支
提交至远程仓库
首先添加远程仓库git remote add origin https://github.com/*/*.git
,如果要删除远程仓库则git remote rm origin
,使用git remote -v
查看远程版本库信息。最后git push -u origin master
将本地代码库上传。此时可能需要输入用户名或密码(可能是token,在个人设置中的Developer setting中生成,参考https://blog.youkuaiyun.com/qq_41646249/article/details/119777084)