ZANARDI Bruno

Software Developper

About
Resume

Git Blog

How To: Move or rename file

previous next

related commands:
add mv rm status

The file is badly named? It’s at the wrong place? Both? No problem, we’ll fix that!

$ mkdir my_dir
$ mv bad_name.file my_dir/good_name.file
$ git add my_dir/good_name.file
$ git rm bad_name.file
$ git commit -m "rename 'bad_name' to 'good_name' then move it to 'my_dir'"

It’s a lot of commands! Do you want a faster way? Allright:

$ git mv bad_name.file my_dir/good_name.file
$ git commit -m "rename 'bad_name' to 'good_name' then move it to 'my_dir'"

It’s better, isn’t it?

previous top next

Reminder

add

Add file content to index if file is untracked or changes in file to index if file is tracked

$ git add <file>

Add multiple files content and/or changes in files to index, depending on tracking status

$ git add <file_1> <file_2> <file_3> ...

mv

Move or rename a file (or both)

$ git mv <file> <destination>

Move or rename a directory (or both)

$ git mv <dir> <destination>

rm

Remove file content from index and working directory

$ git rm <file>

Remove multiple files content from index and working directory

$ git rm <file_1> <file_2> <file_3> ...

status

Shows one to four usefull informations:
. the working branch
. the staged changed files if any
. the unstaged changed files if any
. the untracked files if any

$ git status
previous top next