title | intro | redirect_from | versions | topics | shortTitle | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Moving a file to a new location |
You can move a file to a different directory on {% data variables.product.github %} or by using the command line. |
|
|
|
Move a file |
In addition to changing the file location, you can also update the contents of your file, or give it a new name in the same commit.
Tip
- If you try to move a file in a repository that you don’t have access to, we'll fork the project to your personal account and help you send a pull request to the original repository after you commit your change.
- Some files, such as images, require that you move them from the command line. For more information, see AUTOTITLE.
- {% data reusables.repositories.protected-branches-block-web-edits-uploads %}
- In your repository, browse to the file you want to move. {% data reusables.repositories.edit-file %}
- In the filename field, change the name of the file using these guidelines:
- To move the file into a subfolder, type the name of the folder you want, followed by
/
. Your new folder name becomes a new item in the navigation breadcrumbs. - To move the file into a directory above the file's current location, place your cursor at the beginning of the filename field, then either type
../
to jump up one full directory level, or type thebackspace
key to edit the parent folder's name. {% data reusables.files.write_commit_message %} {% data reusables.files.choose_commit_branch %} {% data reusables.files.propose_file_change %}
- To move the file into a subfolder, type the name of the folder you want, followed by
You can use the command line to move files within a repository by removing the file from the old location and then adding it in the new location.
Many files can be moved directly on {% data variables.product.github %}, but some files, such as images, require that you move them from the command line.
{% data reusables.command_line.manipulating_file_prereqs %}
-
On your computer, move the file to a new location within the directory that was created locally on your computer when you cloned the repository. {% data reusables.command_line.open_the_multi_os_terminal %}
-
Use
git status
to check the old and new file locations.$ git status > # On branch YOUR-BRANCH > # Changes not staged for commit: > # (use "git add/rm <file>..." to update what will be committed) > # (use "git checkout -- <file>..." to discard changes in working directory) > # > # deleted: /OLD-FOLDER/IMAGE.PNG > # > # Untracked files: > # (use "git add <file>..." to include in what will be committed) > # > # /NEW-FOLDER/IMAGE.PNG > # > # no changes added to commit (use "git add" and/or "git commit -a")
{% data reusables.git.stage_for_commit %} This will delete, or git rm
, the file from the old location and add, or git add
, the file to the new location.
$ git add .
# Adds the file to your local repository and stages it for commit.
# {% data reusables.git.unstage-codeblock %}
-
Use
git status
to check the changes staged for commit.$ git status > # On branch YOUR-BRANCH > # Changes to be committed: > # (use "git reset HEAD <file>..." to unstage) > # > # renamed: /old-folder/image.png -> /new-folder/image.png # Displays the changes staged for commit
{% data reusables.git.commit-file %}
$ git commit -m "Move file to new directory"
# Commits the tracked changes and prepares them to be pushed to a remote repository.
# {% data reusables.git.reset-head-to-previous-commit-codeblock %}
{% data reusables.git.git-push %}