git初步使用
git初步使用
主要目的:使用代码控制工具,练习使用git
1、创建新项目
网址如下:
https://github.com/kellyseeme?tab=repositories
注意每个人使用的名称是不一样的,我的名称为kellyseeme
先创建新的项目,如下图所示:
填写名称和描述:
显示完成如下:
2、虚拟机中进行设置
[root@git KELfile]# echo "#KELfile">> README.md [root@git KELfile]# git init Initialized empty Git repository in /root/KELfile/.git/ [root@git KELfile]# git add README.md [root@git KELfile]# git commit -m "first commit" [master (root-commit) 1c87bed] first commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 README.md [root@git KELfile]# git remote add origin git@github.com:kellyseeme/KELfile.git [root@git KELfile]# git push -u origin master |
执行上面的指令,但是一般情况下是不能成功的,需要做的步骤如下:
2.1 修改git配置文件
[root@git .git]# pwd /root/KELfile/.git [root@git .git]# cat config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = ssh://git@github.com:kellyseeme/KELfile.git fetch = +refs/heads/*:refs/remotes/origin/* |
主要修改其url的地址,将其修改为以上格式
2.2 生成本机秘钥
主要就是生成id_rsa.pub,需要输入的地方直接回车即可。
[root@git ~]# cd .ssh [root@git .ssh]# ls -l total 4 -rw-r--r-- 1 root root 803 Jan 23 08:29 known_hosts [root@git .ssh]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: c4:db:c3:05:4a:4e:ed:c2:56:8b:2b:4c:a7:74:97:b0 root@git The key's randomart image is: +--[ RSA 2048]----+ | o.. | | =..o. | | .=* o. | | o.E+=. | | + =S++ | | + . . | | . | | | | | +-----------------+ |
最后生成的格式如下:
[root@git .ssh]# cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxY/dkTMMQJ4/yqin6LEZ8QSkaoOQcGdbXtgc6BDiigDdDE6W6ZI5jdE/cOXsXagHNG7W/XTuTyRe0VhH/bIY6UJ7mwRdATHtnL2np0DqWjQMjgydG9MoyoPAzGa9CpNgcEPZ8XCClkZku7e0q/WxEV7vX9qVSDwLofxHZUSj4+fv+Yxz4g5iyyG7sLQaWplk9tsyFNXDdAl7U2qxD03Fs2BhgbRqteD9ixdaj80b+Qhhq9iN4cs0lJRjDN+BT6HPvcUHAhOllgsuzEbC1LNkzgxy7dIKhFypOYo3hwEoH7s5fOY5siZ9q6LZfTWaUcIjtUWT4gaGUGXQz9LDUsGyAQ== root@git |
2.3 设置登录的ssh秘钥
将公钥拷贝到gitup配置之中。 “Account Settings” > Click “SSH Public Keys” > Click “Add another public key” |
这个主要是将本机的秘钥直接拷贝到git中,然后可以直接连接,从而不会产生没有权限的情况。
2.4 再次提交
[root@git kel]# git push -u origin master Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts. Branch master set up to track remote branch master from origin. Everything up-to-date |
已经提交更新
最后可以查看别人写的文章来学习。善用查询:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000