一.背景

作为一名程序员,怎么能不懂Git那些常用命令呢?于是花费一点时间来总结Git命令。关于安装的话,就不讲了。

二.初始化和帮助

1.配置全局的用户名称和用户邮箱

git config --global user.name "用户名" && git config --global user.email "邮箱账号"

git config --list

git config user.name

[root@centos-master ~]# git config --global user.name "robin" && git config --global user.email "[email protected]"
[root@centos-master ~]# git config --list
user.name=robin
user.email=[email protected]
[root@centos-master ~]# git config user.name
robin
[root@centos-master ~]# 

2.查看帮助

git help -a 

git help <command> 

[root@centos-master ~]# git help -a
usage: git [--version] [--help] [-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>]

available git commands in '/usr/libexec/git-core'

  add                       clean                     fast-import               init                      merge-tree                receive-pack              revert                    tar-tree
  add--interactive          clone                     fetch                     init-db                   mergetool                 reflog                    rm                        unpack-file
  am                        column                    fetch-pack                log                       mktag                     relink                    send-pack                 unpack-objects
  annotate                  commit                    filter-branch             lost-found                mktree                    remote                    sh-i18n--envsubst         update-index
  apply                     commit-tree               fmt-merge-msg             ls-files                  mv                        remote-ext                shell                     update-ref
  archive                   config                    for-each-ref              ls-remote                 name-rev                  remote-fd                 shortlog                  update-server-info
  bisect                    count-objects             format-patch              ls-tree                   notes                     remote-ftp                show                      upload-archive
  bisect--helper            credential                fsck                      mailinfo                  pack-objects              remote-ftps               show-branch               upload-pack
  blame                     credential-cache          fsck-objects              mailsplit                 pack-redundant            remote-http               show-index                var
  branch                    credential-cache--daemon  gc                        merge                     pack-refs                 remote-https              show-ref                  verify-pack
  bundle                    credential-store          get-tar-commit-id         merge-base                patch-id                  remote-testpy             stage                     verify-tag
  cat-file                  describe                  grep                      merge-file                peek-remote               repack                    stash                     web--browse
  check-attr                diff                      hash-object               merge-index               prune                     replace                   status                    whatchanged
  check-ignore              diff-files                help                      merge-octopus             prune-packed              repo-config               stripspace                write-tree
  check-ref-format          diff-index                http-backend              merge-one-file            pull                      request-pull              submodule
  checkout                  diff-tree                 http-fetch                merge-ours                push                      rerere                    submodule--helper
  checkout-index            difftool                  http-push                 merge-recursive           quiltimport               reset                     subtree
  cherry                    difftool--helper          imap-send                 merge-resolve             read-tree                 rev-list                  symbolic-ref
  cherry-pick               fast-export               index-pack                merge-subtree             rebase                    rev-parse                 tag

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

三.站在构建者的角度上需要掌握的命令

1.创建一个仓库

Git系列:常用命令-LMLPHP

 Git系列:常用命令-LMLPHP

 2.基本命令

[root@centos-master git]# ls
[root@centos-master git]# mkdir my-project
[root@centos-master git]# cd my-project/
[root@centos-master my-project]# git init
Initialized empty Git repository in /opt/git/my-project/.git/
[root@centos-master my-project]# touch index.html
[root@centos-master my-project]# git add .
[root@centos-master my-project]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   index.html
#
[root@centos-master my-project]# git commit -m 注释
[master (root-commit) ce8369e] 注释
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 index.html
[root@centos-master my-project]# git status
# On branch master
nothing to commit, working directory clean
[root@centos-master my-project]# git remote add origin https://github.com/CodeInterface/my-project.git
[root@centos-master my-project]# git push -u origin  master
Username for 'https://github.com': CodeInterface
Password for 'https://[email protected]':
Counting objects: 3, done.
Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/CodeInterface/my-project/pull/new/master
remote:
To https://github.com/CodeInterface/my-project.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
[root@centos-master my-project]#

 

11-01 15:25