Git – rename a file

Here’s how I just renamed a file under a git repository since I didn’t want to lose tracking changes by just deleting the old file and adding the new one to the repository. Although I use SmartGit but I had to do the renaming part on the terminal.

1. Rename the file using git command

$ git mv old_filename new_filename

2. Use git status to check the old and new file names.

$ git status
# On branch your-branch
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#     renamed: old_filename -> new_filename
#

3. Commit the file using SmartGit or from terminal using

$ git commit -m "Rename file"

4. Push changes to the remote repository from SmartGit or from terminal using

$ git push
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s