Hopefully you are finding my posts on Git Basics helpful. As of now, as part of the Git Tutorial Series we learned about the changes, the commit to the staging area, viewing the working tree status and pushing the changes to the remote repository.
Continuing the series, today in this blog post, we will learn how to move or rename a file or directory in a Git workspace and update the Index.
The 'git mv' command is used for moving or renaming a file or directory. When you provide <destination> as the same type (file or directory), it renames the <source> file/directory (which must exist) to <destination>.file/directory.
When you provide the last argument (<destination>) as an existing directory, the given sources will be moved into that directory specified.
The index is updated after successful completion, but the change must still need be committed.
Here is the list of command parameters that you will find handy while working with 'git mv' command to move or rename a file or directory:
$ git mv -f <source> <destination>
$ git mv --force <source> <destination>
$ git mv -k <source> <destination>
Was this post useful? If you came to this page by searching online about “git basics” or “git tutorials”, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated.