1. 先安装GIT
# 先检查有没有安装git
[root@mysql ~]# git
-bash: git: command not found
# 没有安装就走下一步
[root@mysql ~]# yum install git
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.7.1-9.el6_9 will be installed
--> Processing Dependency: perl-Git = 1.7.1-9.el6_9 for package: git-1.7.1-9.el6_9.x86_64
--> Processing Dependency: rsync for package: git-1.7.1-9.el6_9.x86_64
--> Processing Dependency: perl(Git) for package: git-1.7.1-9.el6_9.x86_64
--> Processing Dependency: perl(Error) for package: git-1.7.1-9.el6_9.x86_64
--> Running transaction check
---> Package perl-Error.noarch 1:0.17015-4.el6 will be installed
---> Package perl-Git.noarch 0:1.7.1-9.el6_9 will be installed
---> Package rsync.x86_64 0:3.0.6-12.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
git x86_64 1.7.1-9.el6_9 base 4.6 M
Installing for dependencies:
perl-Error noarch 1:0.17015-4.el6 base 29 k
perl-Git noarch 1.7.1-9.el6_9 base 29 k
rsync x86_64 3.0.6-12.el6 base 335 k
Transaction Summary
===========================================================================================================
Install 4 Package(s)
Total download size: 5.0 M
Installed size: 15 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): git-1.7.1-9.el6_9.x86_64.rpm | 4.6 MB 00:01
(2/4): perl-Error-0.17015-4.el6.noarch.rpm | 29 kB 00:00
(3/4): perl-Git-1.7.1-9.el6_9.noarch.rpm | 29 kB 00:00
(4/4): rsync-3.0.6-12.el6.x86_64.rpm | 335 kB 00:00
-----------------------------------------------------------------------------------------------------------
Total 2.5 MB/s | 5.0 MB 00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:perl-Error-0.17015-4.el6.noarch 1/4
Installing : rsync-3.0.6-12.el6.x86_64 2/4
Installing : perl-Git-1.7.1-9.el6_9.noarch 3/4
Installing : git-1.7.1-9.el6_9.x86_64 4/4
Verifying : rsync-3.0.6-12.el6.x86_64 1/4
Verifying : git-1.7.1-9.el6_9.x86_64 2/4
Verifying : perl-Git-1.7.1-9.el6_9.noarch 3/4
Verifying : 1:perl-Error-0.17015-4.el6.noarch 4/4
Installed:
git.x86_64 0:1.7.1-9.el6_9
Dependency Installed:
perl-Error.noarch 1:0.17015-4.el6 perl-Git.noarch 0:1.7.1-9.el6_9 rsync.x86_64 0:3.0.6-12.el6
Complete!
# 再来试一下有没有安装完成
[root@mysql ~]# git
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[--help] COMMAND [ARGS]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help COMMAND' for more information on a specific command.
[root@mysql ~]#
2.生成公钥,添加权限
# 先要生成公钥和私钥
[root@mysql ~]# ssh-keygen
# 一路回车就行
[root@mysql ~]# cd /root/.ssh/
[root@mysql .ssh]# ll
total 8
-rw-r--r--. 1 root root 1675 Nov 13 10:13 id_rsa
-rw-r--r--. 1 root root 401 Nov 13 10:13 id_rsa.pub
[root@mysql .ssh]# cat id_rsa.pub
ssh-rsa ****一大堆字符, 复制这一大堆字符,不要落下字符
[root@mysql .ssh]#
此时公钥已经生成,且已经复制到粘贴板上了, 现需要将公钥给添加至GIT上, 或者公司的GIT上, 或者把.pub
文件交给运维大哥
自行添加过程如下:
github.com
-> 登陆后
->右上角的头像下有Settings
-> SSH and GPG keys
-> New SSH Key
-> 起个名字, 粘贴进去,保存即可
3.克隆代码
[root@mysql .ssh]# cd /home/project/
[root@mysql project]# ll
total 4
drwxr-xr-x. 2 root root 4096 Nov 11 11:02 files
[root@mysql project]# git clone git@github.com:project/project.git
Initialized empty Git repository in /home/project/project/.git/
remote: Enumerating objects: 419, done.
remote: Counting objects: 100% (419/419), done.
remote: Compressing objects: 100% (271/271), done.
remote: Total 419 (delta 274), reused 276 (delta 137), pack-reused 0
Receiving objects: 100% (419/419), 135.49 KiB | 86 KiB/s, done.
Resolving deltas: 100% (274/274), done.
至此安装git
-> 添加git权限
->布置代码
流程结束.