一 。实现这些之前你要先下载git,下载地址:http://git-scm.com/download/win,
下载完成以后,默认安装就行。
可以看到有Bash 有没有很激动,以后经常会用到。
二 。接下来建立远程仓库,我用的是github
注册完账号登录点击箭头所指的按钮,进入页面创建自己的仓库,输入仓库名直接创建就行。
新建仓库什么都没有,你可以右击鼠标新建gitbush窗口,照着上面的命令执行,刷新你的github会看到多了一个文件。
三.具体命令我是参照https://www.yiibai.com/git/git-quick-start.html 执行的,挺全的适合新手
四.总结一下我遇到的问题
fatal: not a git repository (or any of the parent directories): .git
这个错是你没事 git init 这个命令用于初始化现有仓库
你使用push命令时可能会遇到以下问题
Administrator@sa MINGW64 /e/git (master)(原因可能是你在本地(或者服务器上)没有生成ssh key)
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Administrator@sa MINGW64 /e/git (master)
$ git remote add origin [email protected]:TDYRZ/yrz.git #添加一个新的远程库
Administrator@sa MINGW64 /e/git (master)
$ git push origin master
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Administrator@sa MINGW64 /e/git (master)
$ cd ~/.ssh
Administrator@sa MINGW64 ~/.ssh
$ ll #来查看是否有文件id_rsa以及文件id_rsa.pub
Administrator@sa MINGW64 ~/.ssh
$ ls
known_hosts
Administrator@sa MINGW64 ~/.ssh
$ ssh-keygen -t rsa -C "@163.com" #生成你的ssh key
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:iZUsywqMgejyYPSY18L+z+dgNOARCIlrU68szXjO294 [email protected]
The key's randomart image is:
|..o .. |
|+. o .. . |
|+o. .o. + |
|+*= ooo= . |
|==O=.o+oS |
|o=oB... . |
| *.. o |
| oo + .. |
| .o+.Eo. |
+----[SHA256]-----+
Administrator@sa MINGW64 ~/.ssh
$ ssh -v [email protected]
OpenSSH_7.7p1, OpenSSL 1.0.2p 14 Aug 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: [email protected] MAC: compression: none
debug1: kex: client->server cipher: [email protected] MAC: compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /c/Users/Administrator/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:iZUsywqMgejyYPSY18L+z+dgNOARCIlrU68szXjO294 /c/Users/Administrator/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /c/Users/Administrator/.ssh/id_dsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519
debug1: Trying private key: /c/Users/Administrator/.ssh/id_xmss
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
# 提示没有更多的身份验证方法可以 。[email protected]:权限被拒绝(publickey)。
Administrator@sa MINGW64 ~/.ssh
$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-guCKgDb5ZOAw/agent.8692; export SSH_AUTH_SOCK;
SSH_AGENT_PID=10012; export SSH_AGENT_PID;
echo Agent pid 10012;
Administrator@sa MINGW64 ~/.ssh
$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
Administrator@sa MINGW64 ~/.ssh
$ eval 'ssh-agent -s'
SSH_AUTH_SOCK=/tmp/ssh-KSIwZkC0HS0I/agent.4428; export SSH_AUTH_SOCK;
SSH_AGENT_PID=6372; export SSH_AGENT_PID;
echo Agent pid 6372;
Administrator@sa MINGW64 ~/.ssh
$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
#出现这个错
Administrator@sa MINGW64 ~/.ssh
$ ssh-agent bash
Administrator@sa MINGW64 ~/.ssh
$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/Administrator/.ssh/id_rsa (/c/Users/Administrator/.ssh/id_rsa)
#一些ssh key文件路径的信息
Administrator@sa MINGW64 ~/.ssh
$ ls`在这里插入代码片`
id_rsa id_rsa.pub known_hosts
Administrator@sa MINGW64 ~/.ssh
$ vi id_rsa.pub
#此时打开你刚刚生成的id_rsa.pub,将里面的内容复制,进入你的github账号,在settings下,SSH and GPG keys下new SSH key,title随便取一个名字,然后将id_rsa.pub里的内容复制到Key中,完成后Add SSH Key。
Administrator@sa MINGW64 ~/.ssh
$ ssh -T [email protected]
Hi TDYRZ! You've successfully authenticated, but GitHub does not provide shell access.
# 到这问题解决了
你也可以参考这篇博客 https://www.cnblogs.com/wmr95/p/7852832.html
Administrator@sa MINGW64 /e/git (master)
$ git log
commit 3eabbe7704d00dbe1c7cf0c016bee98f091ed39d (HEAD -> master)
Author: yuruizai110 <[email protected]>
Date: Tue Oct 9 17:53:23 2018 +0800
add chinese
commit dfcd98877bd972218bf909a46a8931253ad588e1
Author: yuruizai110 <[email protected]>
Date: Tue Oct 9 17:45:27 2018 +0800
add numbers
commit 20e9d44107e9a7bcca3dcc57cceb33ad719213e9
Author: yuruizai110 <[email protected]>
Date: Tue Oct 9 17:39:42 2018 +0800
hellow git
Administrator@sa MINGW64 /e/git (master)
$ git push -u origin master
To github.com:TDYRZ/yrz.git`
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:TDYRZ/yrz.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
#你有未提交的更改
Administrator@sa MINGW64 /e/git (master)
$ git pull --rebase origin master
From github.com:TDYRZ/yrz
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: hellow git
Applying: add numbers
Applying: add chinese
Administrator@sa MINGW64 /e/git (master)
$ git push -u origin master
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 863 bytes | 431.00 KiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
To github.com:TDYRZ/yrz.git
666b724..3bfcc20 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
五 不扯淡了,看看具体向远程仓库上传自己的项目
七 .总结一下提交命令
git init //初始化本地仓库
git status //查看本地仓库状态
git add (比较坑)
如果只是提交单个项目,直接加项目名就行
git add . --这个命令只会提交当前文件,不包括内容
git commit -m ‘’
git push origin master
场景:LK今天使用lombox插件,想将测试代码提交到自己的仓库中
遇到了一下错误:
Administrator@sa MINGW64 /e/git (master)
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
# 没有读取到远程地址
Please make sure you have the correct access rights
and the repository exists.
Administrator@sa MINGW64 /e/git (master)
$ git remote add origin [email protected]:TDYRZ/lombox.git
Administrator@sa MINGW64 /e/git (master)
$ git push origin master
Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
# 和远程仓库地址不一致
Please make sure you have the correct access rights
and the repository exists.
Administrator@sa MINGW64 /e/git (master)
$ git push -u origin master
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Administrator@sa MINGW64 /e/git (master)
$ git remote -v
origin [email protected]:TDYRZ/lombox.git (fetch)
origin [email protected]:TDYRZ/lombox.git (push)
Administrator@sa MINGW64 /e/git (master)
$ git remote set-url origin https://github.com/TDYRZ/lombox.git
Administrator@sa MINGW64 /e/git (master)
$ git push -u origin master
To https://github.com/TDYRZ/lombox.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/TDYRZ/lombox.git'
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.
Administrator@sa MINGW64 /e/git (master)
$ git push origin master
To https://github.com/TDYRZ/lombox.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/TDYRZ/lombox.git'
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.
# 采用-f命令强推
Administrator@sa MINGW64 /e/git (master)
$ git remote -v
origin https://github.com/TDYRZ/lombox.git (fetch)
origin https://github.com/TDYRZ/lombox.git (push)
Administrator@sa MINGW64 /e/git (master)
$ git push -f origin master
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 4 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (21/21), 2.69 MiB | 362.00 KiB/s, done.
Total 21 (delta 0), reused 0 (delta 0)
To https://github.com/TDYRZ/lombox.git
+ e06f710...6c1decc master -> master (forced update)
还有许多要学习的,以后会持续跟新