---
title: "创建你自己的 git 命令（alias）"
description: "有没有想过把 git 命令缩短一点？你当然可以用 shell alias，但那样得时刻记住上下文，才不会忘记每个 alias 代表什么。其实你可以用 alias 在 git 里定义自己的…"
canonical: https://oozou.com/til/create-your-own-git-commands-aliases-15
locale: zh-Hans
date: 2020-10-13
topic: shell
---

# 创建你自己的 git 命令（alias）

> 有没有想过把 git 命令缩短一点？你当然可以用 shell alias，但那样得时刻记住上下文，才不会忘记每个 alias 代表什么。其实你可以用 alias 在 git 里定义自己的…

Published: 2020-10-13 · Topic: [shell](https://oozou.com/zh-Hans/til-topics/shell) ([markdown](https://oozou.com/zh-Hans/til-topics/shell.md))

有没有想过把 git 命令缩短一点？你当然可以用 shell alias，但那样得时刻记住上下文，才不会忘记每个 alias 代表什么。其实你可以用 alias 在 git 里定义自己的命令。

```shell
git config --global alias.<handle> <command> 
```

举个例子：我懒得敲 *git status*，想把它缩短成 *git s*

```shell
git config --global alias.s status
```

就这样，现在你只要输入 *git s* 就能查看当前 repository 的状态。

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/zh-Hans/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
