git 提交本地代码到github上

 git提交本地代码到github仓库

一.安装git工具,找到代码目录

进入命令行模式

 

二.

 

①git init 初始化

②git add . 把当前所有文件和文件夹添加到仓库 最后有个点

③git commit -m '信息' 提交到仓库

④git remote add origin https://github.com/xuechao2008/thinkcmf-cms.git 加粗去github上找

 

 ⑤git pull origin master 查看master分支

 

⑥git push -u origin master 提交代码到远程仓库

 

 

遇到的问题:

1. git push -u origin master 提交 出现“

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

”错误

解决办法

 

$ ssh-keygen -t rsa -C 'xuechao2008'
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:NwYJT5QYOGl5iHZMwPNzNcWuT7FpKVDU9m7dpZWLL9Q xuechao2008
The key's randomart image is:
+---[RSA 2048]----+
| ..=.=o=+=.      |
|  = X o+=.+      |
| . = o o++ .    .|
|    o o  .o .  .o|
|     o .S.+* .o+o|
|        oo*.oooE.|
|         = .. .  |
|          .  . . |
|              .  |
+----[SHA256]-----+

 查看ssh key

cat /c/Users/Administrator/.ssh/id_rsa

$ cat /c/Users/Administrator/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAzGPGUbMqU6gPgenP2PU9SxtwfnL+HvnrbKeaQnPvhLh1NFdj
C84rI1CDkd85d2SDTYjd0Kb4RK0hAE7XaB2iFoFtwNlh+wSXD5cuL5NokExy+qt6
B7zGCpOCKppwrs7UChy6t6Rs/73remCzwwsczb+4Dz2VuZwL+U8jlzHvq2+tZwoX
EbpwYrlyf8BSgyeboiYuWvWtQdvqZyaXTaDO3lvekdUuLC/OQ83euggx9DPVPWJs
GQqDNLERVTccPRyNm1h6C7PzJYGqMwCsyTKx9jVnuQakP7zjQhAXGHu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FKYR45Bx5/arzHIpg1xkuVuAnECh9GMyV7rTcP/4H8IkhpLI7zEBuy4XG1
ILxLhQECgYBYX3Nx//lEysKsxDZuPZMu+UIg1XZPnhtqfNRq0dPcmvWivzzdeFdm
aaNakIZnx+A8VfN7ZKYiGMiLKYCCsAsodRQjwpuxvfiYsZYMvabyVKGN4K3v4m8u
uWq3pNmbV1dUS2k3cGw0M8rS9lRdXVNZBDYX4yb0ByZEonOlAFniFw==
-----END RSA PRIVATE KEY-----

github上面设置

记得勾选

居然报错了。。。。

Key is invalid. It must begin with 'ssh-ed25519', 'ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', or 'ecdsa-sha2-nistp521'. Check that you're copying the public half of the key

 

未完等继续的

 

2.git commit -m '信息' 提示 fatal: unable to auto-detect email address (got 'Administrator@AFOFD-804180925.(none)') 解决办法

 

解决办法

设置用户名和email

git config --global user.email '2196537621@qq.com'

git config --global user.name 'xuechao2008'

结果:

 

3.git remote add origin 本地仓库关联github仓库 提示 ‘

fatal: remote origin already exists. 

’解决办法

 

解决办法

 git remote rm origin

然后在提交就可以了

 

4. git Push rejected: Push to origin/master was rejected解决办法

强制上传 主要加-f 参数

$ git push -u origin master -f

  

 

posted @ 2018-04-28 15:40  星耀学园  阅读(663)  评论(0编辑  收藏  举报