Skip to content

Commit 2982e4f

Browse files
authored
docs: add shell expansion and Git aliases (#305)
1 parent 1692795 commit 2982e4f

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

docs/best_practices/git_aliases.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
id: git_aliases
3+
title: Git aliases
4+
description: Learn about Git aliases
5+
---
6+
7+
You'll use commands like `git status`, `git log`, `git commit` and `git push` often.
8+
Normally you have to type out Git commands in full before you can use them.
9+
10+
You can save some typing by setting up Git aliases, think of them as "shortcuts" to the full command.
11+
12+
:::tip
13+
Aliases do not replace the original Git commands.
14+
15+
The full length Git commands are _always_ available.
16+
:::
17+
18+
## Local vs global aliases
19+
20+
Aliases can be "local" or "global".
21+
22+
A local alias only works in the repository where you initially setup the alias.
23+
A global alias can be used anywhere on your workstation.
24+
25+
### Setting a local Git alias
26+
27+
Use `git config` to set a local alias:
28+
29+
```git
30+
$ git config alias.ci commit
31+
```
32+
33+
Now you can choose whether you want to type `git commit` or `git ci` when making a new commit in the repository where you set the alias.
34+
35+
### Setting a global Git alias
36+
37+
Use `git config --global` to set a global alias:
38+
39+
```git
40+
$ git config --global alias.ci commit
41+
```
42+
43+
Now you can choose whether you want to type `git commit` or `git ci` when making a new commit in any repository on your workstation.
44+
45+
## Listing current aliases
46+
47+
You can use the `git config --list --local` command to see the local Git configuration.
48+
Conversely, if you want to see the global configuration, use `git config --list --global`.
49+
50+
### Listing local aliases
51+
52+
```git
53+
$ git config --list --local
54+
alias.ci=commit
55+
```
56+
57+
### Listing global aliases
58+
59+
```git
60+
$ git config --list --global
61+
alias.ci=commit
62+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
id: shell_expansion
3+
title: Shell expansion
4+
description: Learn about shell expansion
5+
---
6+
7+
A handy feature of the Bash shell - and most other shells - is that it comes with shell expansion.
8+
9+
You can type a partial Git command name, and Bash will try to expand it to the full command whenever you press <kbd>tab</kbd>.
10+
Shell expansion will also suggest the correct filenames/locations when you use commands like `ls` or `cd`.
11+
12+
:::tip
13+
If the partial command does not uniquely match a command, add some extra letters to make the match unique and press <kbd>tab</kbd> again.
14+
:::
15+
16+
## Shell expansion with Git
17+
18+
Start typing part of the Git command, and use the <kbd>tab</kbd> key to let the shell suggest the rest of the command.
19+
If you don't see any suggestions from the shell, try pressing <kbd>tab</kbd> a second time.
20+
21+
For example:
22+
23+
1. Type `git st`
24+
1. Press <kbd>tab</kbd>
25+
1. Shell expands to `git sta`, but nothing more happens.
26+
1. Press <kbd>tab</kbd> again, you'll see a list of valid options:
27+
```bash
28+
stage stash status
29+
```
30+
1. Type in `t` to make a unique match for `status` and press <kbd>tab</kbd>
31+
1. Now the shell expands to the full command: `git status`
32+
1. Press <kbd>Enter</kbd> to execute the command

sidebars.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
label: "Git sandbox",
3636
items: [
3737
"git_sandbox/setup_your_git_sandbox",
38+
"git_sandbox/shell_expansion",
3839
"git_sandbox/explore_your_git_sandbox",
3940
"git_sandbox/introduction_to_git_status",
4041
"git_sandbox/create_a_new_file_and_track_it",
@@ -58,6 +59,7 @@ module.exports = {
5859
"best_practices/use_a_gitignore_file",
5960
"best_practices/split_up_your_commits",
6061
"best_practices/write_good_commit_messages",
62+
"best_practices/git_aliases",
6163
`best_practices/use_a_linter`,
6264
"best_practices/dealing_with_merges",
6365
"best_practices/use_a_dependency_bot",

0 commit comments

Comments
 (0)