-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add shell expansion and Git aliases (#305)
- Loading branch information
1 parent
1692795
commit 2982e4f
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
id: git_aliases | ||
title: Git aliases | ||
description: Learn about Git aliases | ||
--- | ||
|
||
You'll use commands like `git status`, `git log`, `git commit` and `git push` often. | ||
Normally you have to type out Git commands in full before you can use them. | ||
|
||
You can save some typing by setting up Git aliases, think of them as "shortcuts" to the full command. | ||
|
||
:::tip | ||
Aliases do not replace the original Git commands. | ||
|
||
The full length Git commands are _always_ available. | ||
::: | ||
|
||
## Local vs global aliases | ||
|
||
Aliases can be "local" or "global". | ||
|
||
A local alias only works in the repository where you initially setup the alias. | ||
A global alias can be used anywhere on your workstation. | ||
|
||
### Setting a local Git alias | ||
|
||
Use `git config` to set a local alias: | ||
|
||
```git | ||
$ git config alias.ci commit | ||
``` | ||
|
||
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. | ||
|
||
### Setting a global Git alias | ||
|
||
Use `git config --global` to set a global alias: | ||
|
||
```git | ||
$ git config --global alias.ci commit | ||
``` | ||
|
||
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. | ||
|
||
## Listing current aliases | ||
|
||
You can use the `git config --list --local` command to see the local Git configuration. | ||
Conversely, if you want to see the global configuration, use `git config --list --global`. | ||
|
||
### Listing local aliases | ||
|
||
```git | ||
$ git config --list --local | ||
alias.ci=commit | ||
``` | ||
|
||
### Listing global aliases | ||
|
||
```git | ||
$ git config --list --global | ||
alias.ci=commit | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
id: shell_expansion | ||
title: Shell expansion | ||
description: Learn about shell expansion | ||
--- | ||
|
||
A handy feature of the Bash shell - and most other shells - is that it comes with shell expansion. | ||
|
||
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>. | ||
Shell expansion will also suggest the correct filenames/locations when you use commands like `ls` or `cd`. | ||
|
||
:::tip | ||
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. | ||
::: | ||
|
||
## Shell expansion with Git | ||
|
||
Start typing part of the Git command, and use the <kbd>tab</kbd> key to let the shell suggest the rest of the command. | ||
If you don't see any suggestions from the shell, try pressing <kbd>tab</kbd> a second time. | ||
|
||
For example: | ||
|
||
1. Type `git st` | ||
1. Press <kbd>tab</kbd> | ||
1. Shell expands to `git sta`, but nothing more happens. | ||
1. Press <kbd>tab</kbd> again, you'll see a list of valid options: | ||
```bash | ||
stage stash status | ||
``` | ||
1. Type in `t` to make a unique match for `status` and press <kbd>tab</kbd> | ||
1. Now the shell expands to the full command: `git status` | ||
1. Press <kbd>Enter</kbd> to execute the command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters