(1) git账号注册
在网站(https://github.com )上注册github账号,并登录。
(2)新建仓储(repository)
依次点击右上角+号,选择 New repository之后,输入项目的名称等相关信息,最后点击:Create repository
(3) CentOS下安装git
在root下,输入:yum install git
安装完成后,可查看git的版本, git --version
(4) 生成密匙
使用命令:ssh-keygen来获取密匙
(5)获取密匙
进入/root/.ssh文件夹下,找到一个rsa.pub的文件,运行命令:vim rsa.pub将文件打开,复制文件中的所有内容。
(6)git中输入密匙
将step5 中复制的密匙输入Git
(7)生成Token
在github界面依次点击: setting, Developer settings , personal access tokens, Generate new token 产生令牌(toke).
设置令牌的有效期,权限等参数
点击:Generate token生成令牌,并复制令牌内容
(8)将token直接添加远程仓库链接中, 避免同一个仓库每次提交代码都要输入token了:
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
<your_token>:step 7 保存的token
<USERNAME>:是你自己github的用户名
<REPO>:是你的仓库名称
(9)上传代码
在命令窗口依次输入(第一次上传):
git init (如果提示:Reinitialized existing Git repository in, 该路径中已经存在.git文件了,输入: ls -a查看,有.git 的话,使用 rm -rf .git删除
)
git add file(or) path
git commit -m "first commit" (first commi is the describetion)
git branch -M main
git remote add origin xxx.git (若此时出现:fatal: remote origin already exists.
,则输入: git remote rm origin)
git push -u origin main
若是上传到已存在项目,则输入下图内容
上传完成后出现:
(10)下载代码
git download https://github.com/xxx