Git使用我的武林秘籍技术干货

初入公司,应该这样使用Git

2019-08-04  本文已影响69人  Android师哥
NightRain.png

场景

1.克隆项目代码(默认在主分支上)

G:\test>git clone 项目远程地址
Cloning into 'ProjectDemo'...
remote: Enumerating objects: 6639, done.
remote: Counting objects: 100% (6639/6639), done.
remote: Compressing objects: 100% (4583/4583), done.
remote: Total 6639 (delta 2891), reused 4792 (delta 1747)/s
Receiving objects: 100% (6639/6639), 70.59 MiB | 1.95 MiB/s, done.
Resolving deltas: 100% (2891/2891), done.
Checking out files: 100% (3415/3415), done.

2.查看远程分支和本地分支状态(注意要进入项目目录)

//查看本地分支状态
G:\test\ProjectDemo>git branch
* master
//查看远程分支状态
G:\test\ProjectDemo>git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev-test
  remotes/origin/master
  remotes/origin/test1
  remotes/origin/test2

3. 创建本地分支并跟踪远程分支(dev-test为分支名)

G:\test\ProjectDemo>git checkout -b dev-test origin/dev-test
Checking out files: 100% (1291/1291), done.
Switched to a new branch 'dev-test'
Branch 'dev-test' set up to track remote branch 'dev-test' from 'origin'.

4. 查看分支跟踪情况

G:\test\ProjectDemo>git branch -vv
* dev-test d62efae [origin/dev-test] ......
  master    e1b4220 [origin/master] ......

5.常用命令

命令 说明
git config --global user.name "your name" 修改Git昵称
git config --global user.email "your name" 修改Git邮箱
git config user.name 查看Git昵称
git congig user.email 查看你Git邮箱
git add . 将当前目录添加到git索引库
git commit -m "提交说明" 将索引库项目提交到本地仓库
git branch 查看本地分支
git branch -a 查看远程分支
git branch -vv 查看本地分支和远程分支跟踪情况
git branch new_dev 创建一个名为new_dev的分支
git checkout new_dev 切换到new_dev分支
git checkout -b new_dev 创建new_dev分支并切换到此分支
git checkout -b dev origin/dev 创建dev分支并跟踪远程dev分支
git status 查看项目状态(是否有需要操作之类)
git push 将本地仓库推送到远程仓库
git pull 从远处仓库更新代码到本地
上一篇 下一篇

猜你喜欢

热点阅读