Git的使用--如何将本地项目上传到Github
//==========Git的使用—如何将本地项目上传到Github=====以下为总结笔记,不适合初学者================
初学者请移步大牛网站 https://git-scm.com/book/zh/v2
//git config
git config —global user.name 932432866
git config —global user.email 932432866@qq.com
git config —global pull.rebase true
敲git config —list确认
//常用
git init //把这个目录变成Git可以管理的仓库
git add README.md //文件添加到仓库
git add . //不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了
git commit -m “first commit” //把文件提交到仓库
git remote add origin git@github.com:932432866/MCGS.git //关联远程仓库
git push -u origin master //把本地库的所有内容推送到远程库上 以后再上传就不需要 -u 参数了
//创建本地SSH KEY 切换到c/Users/Jokey/
ssh-keygen -t rsa -C “932432866@qq.com”
1)路径确认,直接按回车存默认路径即可
2)直接回车键,这里我们不使用密码进行登录, 用密码太麻烦;
3)直接回车键
//在github网页配置SSH KEY
1)setting 略
//能测通?Hi 932432866! You’ve successfully authenticated, but GitHub does not provide shell access.
ssh -T git@github.com
//将本地的仓库关联到github上
git remote add origin https://github.com/932432866/MCGS
//把代码上传到github仓库
git push -u origin master
PS:如果仍然无法成功拉代码,提示:
sign_and_send_pubkey: signing failed: agent refused operation 10072800@gerritro.zte.com.cn: Permission denied (publickey). fatal: Could not read from remote repository.
在终端中再输入:ssh-add
//遇到如下问题
$ git push -u origin master
To https://github.com/932432866/MCGS
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://github.com/932432866/MCGS‘
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push —help’ for details.
//解决
$ git pull —rebase origin master
From https://github.com/932432866/MCGS
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it…
Applying: first commit
Applying: add pictures
还没有评论,来说两句吧...