2019-10-12 21:52:04 +05:30
---
2020-10-24 23:57:45 +05:30
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2019-10-12 21:52:04 +05:30
type: howto
---
2015-09-11 14:41:01 +05:30
2021-03-11 19:13:27 +05:30
# Add a file to a repository **(FREE)**
2019-10-12 21:52:04 +05:30
Adding files to a repository is a small, but key task. Bringing files in to a repository,
such as code, images, or documents, allows them to be tracked by Git, even though they
may have been created elsewhere.
You can add a file to a repository in your [terminal ](#add-a-file-using-the-command-line ), and
then push to GitLab. You can also use the [web interface ](../user/project/repository/web_editor.md#upload-a-file ),
which may be a simpler solution.
If you need to create a file first, for example a `README.md` text file, that can
also be done from the [terminal ](command-line-commands.md#create-a-text-file-in-the-current-directory ) or
2016-11-03 12:29:30 +05:30
[web interface ](../user/project/repository/web_editor.md#create-a-file ).
2019-10-12 21:52:04 +05:30
## Add a file using the command line
Open a [terminal/shell ](command-line-commands.md ), and change into the folder of your
GitLab project. This usually means running the following command until you get
to the desired destination:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
cd < destination folder >
```
2022-08-13 15:12:31 +05:30
[Create a new branch ](../tutorials/make_your_first_git_commit.md#create-a-branch-and-make-changes ) to add your file into. Submitting changes directly
2021-01-03 14:25:43 +05:30
to the default branch should be avoided unless your project is very small and you're the
only person working on it.
2021-09-04 01:27:46 +05:30
You can also [switch to an existing branch ](start-using-git.md#switch-to-a-branch )
2019-10-12 21:52:04 +05:30
if you have one already.
Using your standard tool for copying files (for example, Finder in macOS, or File Explorer
2021-01-03 14:25:43 +05:30
on Windows), put the file into a directory within the GitLab project.
2019-10-12 21:52:04 +05:30
2021-01-03 14:25:43 +05:30
Check if your file is actually present in the directory (if you're on Windows,
2019-10-12 21:52:04 +05:30
use `dir` instead):
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
ls
```
You should see the name of the file in the list shown.
Check the status:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
git status
```
Your file's name should appear in red, so `git` took notice of it! Now add it
to the repository:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
git add < name of file >
```
Check the status again, your file's name should have turned green:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
git status
```
Commit (save) your file to the repository:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
git commit -m "DESCRIBE COMMIT IN A FEW WORDS"
```
Now you can push (send) your changes (in the branch `<branch-name>` ) to GitLab
2019-12-04 20:38:33 +05:30
(the Git remote named 'origin'):
2019-10-12 21:52:04 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
git push origin < branch-name >
```
2021-01-03 14:25:43 +05:30
Your image is added to your branch in your repository in GitLab.
2019-10-12 21:52:04 +05:30
<!-- ## Troubleshooting
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.
Each scenario can be a third-level heading, e.g. `### Getting error message X` .
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. -->