# 1.3 Ubuntu18 git命令使用总结

## 摘要

本文记录了 Ubuntu18 git命令使用总结，主要包括git的指令使用帮助，本文不是指导如何调试代码和修复代码，具体内容见文中内容所示。

* [x] Edit By Porter, 积水成渊,蛟龙生焉。

文章同步于: [我的gitbook](https://porter.gitbook.io/)

## git 相关命令学习

### 一、[git remote 命令用法](https://www.git-scm.com/docs/git-remote)

#### 1.1 [git remote 命令用法](https://www.git-scm.com/docs/git-remote)

```bash
git remote [-v | --verbose]  #不带参数，列出已经存在的远程分支
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>…​
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>…​
git remote prune [-n | --dry-run] <name>…​
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)…​]
```

### 二、例程代码

#### 2.1 例程代码

* 查看当前的远程库&#x20;

```
$ git remote -v
  origin git://github.com/schacon/ticgit.git如果有多个远程仓库,此命令将全部列出.比如在我的 Grit 项目中,可以看到.

$ git remote #不带参数，列出已经存在的远程分支
  origin

# 如果提示：error: 无法推送一些引用到 'https://github.com/porterpan/gitbook-tutorial.git'
# 提示：更新被拒绝，因为您当前分支的最新提交落后于其对应的远程分支。
# 提示：再次推送前，先与远程变更合并（如 'git pull ...'）。详见
# 提示：'git push --help' 中的 'Note about fast-forwards' 小节。

$ git fetch origin
$ git merge origin/mastergit
```

#### 正常流程

* 如果都是自己在开发的类，当然优先使用pull->commit->push，为什么我更倾向这种方式呢，因为这样会减少Git没有必要的merge。
* 如果有冲突的情况下，先pull了会出现什么问题呢？ 如果你的判断失误，在本地修改与远程代码有冲突的情况下，先执行了git-pull，即使是这样也不用担心，git会给你一个错误提示，这时候你再去执行commit->pull->push也是没有问题的。

### git代理配置

#### git设置代理

* 代理类型是socks5

  ```
  git config --global http.proxy socks5://127.0.0.1:1080
  git config --global https.proxy socks5://127.0.0.1:1080
  ```
* 代理类型是普通的http/https

  ```
  git config --global https.proxy http://127.0.0.1:1080
  git config --global https.proxy https://127.0.0.1:1080
  ```

#### git取消代理

```
git config --global --unset http.proxy
git config --global --unset https.proxy
```
