---
title: "使用 Git 的 aliases 功能"
description: "Git 允許你透過 config 在內部建立 alias。你的全域 config 應該位於 ~/.gitconfig"
canonical: https://oozou.com/til/using-git-s-aliases-feature-61
locale: zh-Hant
date: 2020-10-13
topic: shell
---

# 使用 Git 的 aliases 功能

> Git 允許你透過 config 在內部建立 alias。你的全域 config 應該位於 ~/.gitconfig

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

Git 允許你透過 config 在內部建立 alias。你的全域 config 應該位於 *~/.gitconfig*

```git
[alias]
  aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
  count = shortlog -sn
  l = log
  co = checkout
  ca = commit -C HEAD --amend
  c  = commit
  cm = commit -m
  a  = add
  s  = status
  b  = branch
  p  = push
  mt = mergetool
  dt = difftool
  o  = origin
  rc = rebase --continue
  rs = rebase --skip
  pd  = !git checkout develop && git pull origin develop && git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d && git fetch --prune origin
  pm  = !git checkout master && git pull origin master && git branch --merged | grep -v '*' | grep -v 'develop' | xargs git branch -d && git fetch --prune origin
  pr = pull-request -c -m
```

大多數都不言自明...

*git pd*（prune develop）- 切換到 develop、拉取最新變更、刪除 develop 以外所有過時的 branch（也會刪掉 master）

*git pm*（prune master）- 對 master 做和 prune develop 一樣的事

---

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

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