Git Basics: How to move or rename a file or directory in a workspace?


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.

 

How to move or rename a file or directory in Git workspace (www.kunal-chowdhury.com)

 

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:

 

Force renaming or moving of a file even if the target exists:

$ git mv -f <source> <destination>

$ git mv --force <source> <destination>

 

Skip move or rename actions on an error condition:

$ 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.

 

 

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top