CentOS配置Git

阿里云ECS服务器上用CentOS配置Git

查看当前服务器是否有安装git

git --version

如果有,那么查看版本号,是否是你想要的或最新的版本

1
2
3
┌─[root@sun] - [/] - [Thu Jan 20, 11:32]
└─[$]> git --version
git version 1.8.3.1

如果不是自己想要的版本,那么执行以下命令可卸载当前版本

yum remove git

查看当前系统的git

git

cd到home目录,创建一个目录qwq,尽量与你git远程存储库的一样,这里将存放着你的git本地文件

mkdir qwq

cd进入到刚刚创建的目录中,把文件夹初始化成git仓库

git init

把需要存储的文件存储到本地git里

git add 文件名称

设置邮箱和用户名

1
2
git config --global user.email "xxxx@xxxxxxx.com"
git config --global user.name "Your Name"

接下来提交到仓库中

git commit -m"first commit"

查看当前仓库的文件

git ls-files

接下来到了传递到远程仓库的时候了

首先先生成自己的密钥

ssh-keygen -t rsa

生成成功可以看见当前生成的密钥路径

cd 到此目录 .ssh是属于隐藏目录,可用ls -a先行浏览再进入

进入.ssh目录后查看当前密钥文件,并把文件内容复制下来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/usr/bin/which: no .ssh in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
┌─[root@sun] - [/] - [Thu Jan 20, 11:46]
└─[$]> cd root
┌─[root@sun] - [~] - [Thu Jan 20, 11:46]
└─[$]> ls
┌─[root@sun] - [~] - [Thu Jan 20, 11:46]
└─[$]> ls -al
total 116
dr-xr-x---. 7 root root 4096 Jan 20 11:46 .
dr-xr-xr-x. 18 root root 4096 Jan 17 16:01 ..
-rw------- 1 root root 7953 Jan 19 23:59 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
drwx------ 3 root root 4096 Dec 27 09:52 .cache
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
-rw-r--r-- 1 root root 55 Jan 19 18:04 .gitconfig
drwxr-xr-x 12 root root 4096 Jan 19 23:15 .oh-my-zsh
drwxr-xr-x 2 root root 4096 Dec 27 09:52 .pip
drwxr----- 3 root root 4096 Jan 17 16:15 .pki
-rw-r--r-- 1 root root 206 Jan 17 16:01 .pydistutils.cfg
drwx------ 2 root root 4096 Jan 19 17:53 .ssh
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
-rw------- 1 root root 2278 Jan 19 23:20 .viminfo
-rw-r--r-- 1 root root 36647 Jan 20 10:04 .zcompdump-sun-5.0.2
-rw------- 1 root root 2289 Jan 20 11:46 .zsh_history
-rw-r--r-- 1 root root 4167 Jan 20 10:00 .zshrc
┌─[root@sun] - [~] - [Thu Jan 20, 11:46]
└─[$]> cd .ssh
┌─[root@sun] - [~/.ssh] - [Thu Jan 20, 11:46]
└─[$]> ls
authorized_keys id_rsa id_rsa.pub known_hosts
┌─[root@sun] - [~/.ssh] - [Thu Jan 20, 11:46]
└─[$]> more id_rsa.pub
ssh-rsa ......bImXX1 root@sun

打开github网站并登陆,点击右上角头像,再点击Settings

找到SSH and GPG keys并点击

点击右上角New SSH key添加新密钥

然后完成以下步骤并保存

回到服务器远程连接git并把本地仓库的文件克隆上去

1
2
# git remote add origin git@github.com:自己的git组织名称/仓库名称.git
# git push -u origin master

本地获取远程仓库的文件

1
git clone git://github.com/组织名称/文件仓库名称.git