Add files to your branch
You can use Git to add files to a Git repository.
Add files to a Git repository
To add a new file from the command line:
-
Open a terminal.
-
Change directories until you are in your project’s folder.
cd my-project
-
Choose a Git branch to work in.
- To create a branch:
git checkout -b <branchname>
- To switch to an existing branch:
git checkout <branchname>
- To create a branch:
-
Copy the file you want to add into the directory where you want to add it.
-
Confirm that your file is in the directory:
- Windows:
dir
- All other operating systems:
ls
The filename should be displayed.
- Windows:
-
Check the status of the file:
git status
The filename should be in red. The file is in your file system, but Git isn’t tracking it yet.
-
Tell Git to track the file:
git add <filename>
-
Check the status of the file again:
git status
The filename should be green. The file is tracked locally by Git, but has not been committed and pushed.
Add a file to the last commit
To add changes to a file to the last commit, instead of to a new commit:
git add <filename>
git commit --amend
Append --no-edit
to the commit
command if you do not want to edit the commit message.
Related topics
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support