git基本操作与常用命令

2019-03-30  本文已影响0人  bearPotMan

1. git基本操作

1.1 客户端安装

官网下载git客户端 并完成安装,详细过程不再赘述!

启动 Git Bash 检验。
命令:git 或者 git --version

wj@localhost MINGW64 /d
$ git --version
git version 2.20.1.windows.1

1.2 git 用户信息配置

  1. 配置用户信息

    命令:git config --global user.name "你的名字"
    git config --global user.email "你的邮箱"

wj@localhost MINGW64 /d
$ git config --global user.name "wangjun"

wj@localhost MINGW64 /d
$ git config --global user.email "wangjun9406@163.com"
  1. 查看配置信息

    命令:git config --global user.name

    git config --global user.email

wj@localhost MINGW64 /d
$ git config --global user.name
wangjun

wj@localhost MINGW64 /d
$ git config --global user.email
wangjun9406@163.com
  1. 修改配置信息并查看
wj@localhost MINGW64 /d
$ git config --global user.name "wj"

wj@localhost MINGW64 /d
$ git config --global user.name
wj

wj@localhost MINGW64 /d
$ git config --global user.email "2370959316@qq.com"

wj@localhost MINGW64 /d
$ git config --global user.email
2370959316@qq.com

1.3 创建本地库并初始化

命令:git init

wj@localhost MINGW64 /d
$ cd workspace/

wj@localhost MINGW64 /d/workspace
$ mkdir git-learning

wj@localhost MINGW64 /d/workspace
$ cd git-learning/

wj@localhost MINGW64 /d/workspace/git-learning
$ git init
Initialized empty Git repository in D:/workspace/git-learning/.git/

1.4 添加文件至缓存区

主要命令(添加文件至缓存区):git add yourfile

辅助命令(查看当前仓库/分支状态):git status

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ touch README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ vim README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        README.md

nothing added to commit but untracked files present (use "git add" to track)

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git add README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   README.md

1.5 提交缓存区文件至本地库

命令:git commit -m "本次提交说明"

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git commit -m "add README.md file"
[master (root-commit) 0fd2779] add README.md file
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git status
On branch master
nothing to commit, working tree clean

1.6 本地库与远程库同步

命令:git remote add origin 仓库地址

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git remote add origin https://github.com/bearPotMan/git-learning.git

1.7 推送本地库内容至远程库

命令:git push -u origin master

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 252 bytes | 252.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bearPotMan/git-learning.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

以上就是最基本的第一次记录提交!

之后的文件的修改与提交使用的命令主要有三个:

2. git 常用命令

其他命令后续用的比较熟练了再更新吧!

我是bearPotMan,一个经验不足的十八线演(码)员(农)。
Know everything,control everything!

上一篇 下一篇

猜你喜欢

热点阅读