`
TimerBin
  • 浏览: 355227 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

linux 使用Git部署应用常用命令总结

阅读更多

最近将项目的版本管理工具由SVN转为Git,下面记录下在此过程中遇到的问题:

 

第一步:检验当前linux系统是否已经安装git

 

 

[root@root root]# 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]
........
See 'git help COMMAND' for more information on a specific command.

   以上内容表示已经安装git,可以直接跳到第三步。

 

 

第二步:安装git

    

yum install git

    注:如果非root用户时请执行sudo yum install git

 

第三步:验证git是否安装成功

  

 

[root@root root]# git --version
git version 1.7.1

 

 

第四步:设置Git 用户的name和email(第一次需要设置)

 

 

 $ git config --global user.name "timerbin"
 $ git config --global user.email "timerbin@xxxx.net"

 

 

第五步:配置git-ssh秘钥,在linux系统中执行如下命令

    

$ ssh-keygen -t rsa -C "timerbin"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/timerbin/.ssh/id_rsa): 
Created directory '/home/timerbin/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/timerbin/.ssh/id_rsa.
Your public key has been saved in /home/timerbin/.ssh/id_rsa.pub.
The key fingerprint is:
c4:87:78:f9:de:5a:6e:6b:24:80:d2:94:74:5f:b9:c7 timerbin
The key's randomart image is:
+--[ RSA 2048]----+
|     ....   ..   |
|      o+ + ..    |
|     o..* o  o   |
|    . oo.o  . E  |
|     .  S..  .   |
|         ....    |
|          .oo    |
|           +o    |
|          .oo.   |
+-----------------+

 

 

第六步:将第五步生成的rsa公钥上传到git用户,具体如下所示:

Profile settings -->SSH key -->add sshKe。



 

注:其中的SSHkey的内容来源于第五步生成的id_rsa.pub

 

第六步:在linux 命令行中输入如下内容,验证ssh授权是否成功:

 

$ ssh -T git@git.com
Address xxx.xxx.xxx.xxx maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Welcome to GitLab, timerbin!

    如果出现以上内容表示验证成功

 

第七步:在linux系统中执行如下命令,新建git克隆

   

git clone git@git.timerbin.com:timerbin/timer.git

   

    注:如果在执行时提示出如下错误

 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @        WARNING: UNPROTECTED PRIVATE KEY FILE!          @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 Permissions 0644 for 'id_rsa' are too open.
 It is required that your private key files are NOT accessible by others.
 This private key will be ignored.
 bad permissions: ignore key: id_rsa
 root@xxx.xxx.xxx.xxx's password:

   

   请到~/.ssh/目录下执行 chmod 600 id_rsa 为id_rsa进行授权

 

第七步:linux系统下git部署项目时常用命令:

        查看当前项目正在使用的分支和状态:git status

        查看项目远程分支:git branch -a

        查看项目本地分支:git branch

        拉取项目本地分支:git pull origin dev      注:dev远程分支分支名称

       切换本地项目分支:git checkout dev

 

 

 

 

 

 

    

 

 

 

 

 

 

    

   

 

 

  • 大小: 49.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics