Github常用指令

  • 上传本地代码到Github

创建本地仓库:

git init

将本地仓库的全部文件添加进Git:

git add .

添加本次提交信息:

git commit -m "提交信息"

将本地仓库关联到Github:

git remote add origin https://github.com/yourname/repositoryname.git

上传到Github(输入Github的账号密码):

git push -u origin master

  • 创建本地Git仓库和GitHub仓库连接

创建SSH Key(注册GIthub的邮箱):

ssh-keygen -t rsa -C "[email protected]"

在用户主目录(C:\Users\Administrator)下,看看有没有.ssh文件,如果有,再看文件下有没有id_rsa和id_rsa.pub这两个文件,这两个就是SSHKey的秘钥对,id_rsa是私钥,不能泄露,id_rsa.pub是公钥。在GitHub上打开“Account settings”–“SSH Keys”页面,然后点击“Add SSH Key”,填上Title(随意写),在Key文本框里粘贴 id_rsa.pub文件里的全部内容。

验证是否成功:

ssh -T git@github.com

设置username和email(用于记录每次commit):

git config --global user.name  "yourname"
git config --global user.email "[email protected]"

  • 常见错误

一、输入git remote add origin https://github.com/yourname/repositoryname.git
提示出错信息:fatal: remote origin already exists.
解决办法如下:
1、先输入git remote rm origin
2、修改gitconfig文件,删掉[remote “origin”]那一行

二、如果输入$ git push origin master
提示出错信息:error:failed to push som refs to …
解决办法如下:
1、先输入git pull origin master,再输入git push origin master
2、如果出现报错 fatal: Couldn’t find remote ref master或者fatal: ‘origin’ does not appear to be a git repository以及fatal: Could not read from remote repository.则需要重新输入
git remote add origin https://github.com/yourname/repositoryname.git

猜你喜欢

转载自blog.csdn.net/changyan_123/article/details/80658753