Git开发实战(一)之Git的安装配置与基本操作

Git安装与配置实战
本文详细介绍了Git在不同操作系统下的安装方法,包括Linux、MacOS和Windows,并演示了如何进行全局及局部配置。此外,还提供了实用命令示例,帮助初学者快速掌握Git的基本操作。

一、Git的安装

      1.Linux

  • apt-get insatll git    ubuntu
  • yum install git         centos/redhat

      2.Mac OS

      xcode应该自带了

      3.Windows

      也有客户端(实际上就是windows上的命令行)git官网 git-scm.com

      4.提示

  • 不要迷信图形化工具!
  • 好用的Git是没有图形化工具的!命令行是王道!特别是新手,不要偷懒!
  • 本《Git开发实战》系列博客是在Windows的git_shell中进行命令行操作的

二、Git的配置和基本操作

      1.Git安装成功后,使用git命令,查看git的一些常见命令

aibin@XiaoAibin MINGW64 ~/Desktop
$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

      2.可以通过git --version命令查看当前git的版本信息

aibin@XiaoAibin MINGW64 ~/Desktop
$ git --version
git version 2.10.0.windows.1

      3.配置文件,包括全局配置和局部配置

     

      全局配置:

      (1)使用cat ~/.gitconfig命令就可以进入到git的home目录下并显示出git的全局配置信息

aibin@XiaoAibin MINGW64 ~/Desktop
$ cat ~/.gitconfig

      (2)使用vim ~/.gitconfig命令可以编辑git的全局配置信息文件

aibin@XiaoAibin MINGW64 ~/Desktop
$ vim ~/.gitconfig

      局部配置:

      (1)首先,我在桌面上使用mkdir命令创建一个目录test-git,然后用cd命令切换到这个目录下,然后使用ls -altrh查看这个目录下有什么文件,发现新创建的目录下,什么也没有!

aibin@XiaoAibin MINGW64 ~/Desktop
$ mkdir test_git

aibin@XiaoAibin MINGW64 ~/Desktop
$ cd test_git

aibin@XiaoAibin MINGW64 ~/Desktop/test_git
$ ls -altrh
total 28K
drwxr-xr-x 1 aibin 197609 0 10月 23 14:50 ../
drwxr-xr-x 1 aibin 197609 0 10月 23 14:50 ./

      (2)然后使用git init命令对test-git这个目录进行了git版本控制,然后会发现这个目录下会多出一个.git的目录

aibin@XiaoAibin MINGW64 ~/Desktop/test_git
$ git init .
Initialized empty Git repository in C:/Users/aibin/Desktop/test_git/.git/

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ ls -altrh
total 32K
drwxr-xr-x 1 aibin 197609 0 10月 23 14:50 ../
drwxr-xr-x 1 aibin 197609 0 10月 23 14:52 ./
drwxr-xr-x 1 aibin 197609 0 10月 23 14:52 .git/

       (3)接着使用vim .git/ 命令,我们可以看到.git下面有好几个目录,如图所示:

     

      (4)我们用上下键移动到config这个文件上,然后进入这个文件,我们可以看到如下配置信息:

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[user]
        name = kevinShaw
        email = aibinxiao@126.com

      (5)我们可以直接在这个文件中修改配置信息,当然我们也可以通过命令git config user.name kevin进行修改

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git config user.name kevinShaw

 

本文为原创文章,如果对你有一点点的帮助,别忘了点赞哦!比心!如需转载,请注明出处,谢谢!

 

转载于:https://my.oschina.net/aibinxiao/blog/1554908

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值