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.
Open a terminal/shell, and change into the folder of your GitLab project. This usually means running the following command until you get to the desired destination:
cd <destination folder>
Create a branch to add your file to, before it is added to the master
(main) branch of the project. It is not strictly necessary, but working directly in
master branch is not recommended unless your project is very small, and you are
the only person working on it. You can switch to an existing branch,
if you have one already.
Using your standard tool for copying files (for example, Finder in macOS, or File Explorer in Windows), put the file into a directory within the GitLab project.
Check if your file is actually present in the directory (if you are in Windows,
You should see the name of the file in the list shown.
Check the status:
Your file’s name should appear in red, so
git took notice of it! Now add it
to the repository:
git add <name of file>
Check the status again, your file’s name should have turned green:
Commit (save) your file to the repository:
git commit -m "DESCRIBE COMMIT IN A FEW WORDS"
Now you can push (send) your changes (in the branch
<branch-name>) to GitLab
(the Git remote named ‘origin’):
git push origin <branch-name>
Your image will be added to your branch in your repository in GitLab.