2019-10-12 21:52:04 +05:30
---
2020-10-24 23:57:45 +05:30
stage: Create
group: Source Code
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2019-10-12 21:52:04 +05:30
---
2016-11-03 12:29:30 +05:30
2021-03-11 19:13:27 +05:30
# Edit files through the command line **(FREE)**
2015-09-11 14:41:01 +05:30
2021-01-29 00:20:46 +05:30
When [working with Git from the command line ](start-using-git.md ), you need to
2019-10-12 21:52:04 +05:30
use more than just the Git commands. There are several basic commands that you should
2022-03-02 08:16:31 +05:30
learn to make full use of the command line.
2016-11-03 12:29:30 +05:30
2019-10-12 21:52:04 +05:30
## Start working on your project
2015-09-11 14:41:01 +05:30
2019-12-04 20:38:33 +05:30
To work on a Git project locally (from your own computer), with the command line,
2021-01-29 00:20:46 +05:30
first you need to [clone (copy) it ](start-using-git.md#clone-a-repository ) to
2019-10-12 21:52:04 +05:30
your computer.
2016-11-03 12:29:30 +05:30
2019-10-12 21:52:04 +05:30
## Working with files on the command line
2015-09-11 14:41:01 +05:30
2019-10-12 21:52:04 +05:30
This section has examples of some basic shell commands that you might find useful.
For more information, search the web for _bash commands_ .
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
Alternatively, you can edit files using your choice of editor (IDE), or the GitLab user
interface (not locally).
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
### Common commands
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
The list below is not exhaustive, but contains many of the most commonly used commands.
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
| Command | Description |
|--------------------------------|---------------------------------------------|
| `cd NAME-OF-DIRECTORY` | Go into a directory to work in it |
| `cd ..` | Go back one directory |
2021-04-29 21:17:54 +05:30
| `ls` | List what's in the current directory |
| `ls a*` | List what's in the current directory that starts with `a` |
| `ls *.md` | List what's in the current directory that ends with `.md` |
2019-10-12 21:52:04 +05:30
| `mkdir NAME-OF-YOUR-DIRECTORY` | Create a new directory |
| `cat README.md` | Display the contents of a [text file you created previously ](#create-a-text-file-in-the-current-directory ) |
| `pwd` | Show the current directory |
| `clear` | Clear the shell window |
2016-11-03 12:29:30 +05:30
2019-10-12 21:52:04 +05:30
### Create a text file in the current directory
2015-09-11 14:41:01 +05:30
2019-10-12 21:52:04 +05:30
To create a text file from the command line, for example `README.md` , follow these
steps:
2016-11-03 12:29:30 +05:30
2020-04-22 19:07:51 +05:30
```shell
2015-09-11 14:41:01 +05:30
touch README.md
nano README.md
#### ADD YOUR INFORMATION
#### Press: control + X
#### Type: Y
#### Press: enter
```
2019-10-12 21:52:04 +05:30
### Remove a file or directory
2018-11-08 19:23:39 +05:30
2021-01-29 00:20:46 +05:30
It's easy to delete (remove) a file or directory, but be careful:
2016-11-03 12:29:30 +05:30
2021-02-22 17:27:13 +05:30
WARNING:
2019-10-12 21:52:04 +05:30
This will **permanently** delete a file.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
```shell
2015-09-11 14:41:01 +05:30
rm NAME-OF-FILE
```
2021-02-22 17:27:13 +05:30
WARNING:
2019-10-12 21:52:04 +05:30
This will **permanently** delete a directory and **all** of its contents.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
```shell
2018-10-15 14:42:47 +05:30
rm -r NAME-OF-DIRECTORY
2015-09-11 14:41:01 +05:30
```
2019-10-12 21:52:04 +05:30
### View and Execute commands from history
You can view the history of all the commands you executed from the command line,
and then execute any of them again, if needed.
First, list the commands you executed previously:
2016-11-03 12:29:30 +05:30
2020-04-22 19:07:51 +05:30
```shell
2015-09-11 14:41:01 +05:30
history
```
2019-10-12 21:52:04 +05:30
Then, choose a command from the list and check the number next to the command (`123`,
for example) . Execute the same full command with:
2018-11-08 19:23:39 +05:30
2020-04-22 19:07:51 +05:30
```shell
2018-11-08 19:23:39 +05:30
!123
```
2015-09-11 14:41:01 +05:30
### Carry out commands for which the account you are using lacks authority
2016-11-03 12:29:30 +05:30
2019-10-12 21:52:04 +05:30
Not all commands can be executed from a basic user account on a computer, you may
need administrator's rights to execute commands that affect the system, or try to access
protected data, for example. You can use `sudo` to execute these commands, but you
2021-01-29 00:20:46 +05:30
might be asked for an administrator password.
2016-11-03 12:29:30 +05:30
2020-04-22 19:07:51 +05:30
```shell
2019-10-12 21:52:04 +05:30
sudo RESTRICTED-COMMAND
2015-09-11 14:41:01 +05:30
```
2015-09-25 12:07:36 +05:30
2021-02-22 17:27:13 +05:30
WARNING:
2019-09-30 21:07:59 +05:30
Be careful of the commands you run with `sudo` . Certain commands may cause
2019-10-12 21:52:04 +05:30
damage to your data or system.
2019-09-30 21:07:59 +05:30
2021-03-11 19:13:27 +05:30
## Sample Git task flow
2016-11-03 12:29:30 +05:30
2021-03-11 19:13:27 +05:30
If you're completely new to Git, looking through some [sample task flows ](https://rogerdudler.github.io/git-guide/ )
2021-01-29 00:20:46 +05:30
may help you understand the best practices for using these commands as you work.
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
<!-- ## Troubleshooting
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
2018-12-05 23:21:45 +05:30
2023-01-13 00:05:48 +05:30
Each scenario can be a third-level heading, for example `### Getting error message X` .
2019-10-12 21:52:04 +05:30
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->