Renaming files in git

I have two files checked into github.

  1. index.html
  2. backup.html

Now I want to rename backup.html into index.html and vice versa. I don’t really care about maintaining the change history for each file. How do I do this in git ?

  • Maintainig very own vendor with composer and git Symfony2 Bundle
  • Is there a better way to find out if a local git branch exists?
  • git: how to revert file which is in .gitignore
  • fatal: bad default revision 'HEAD'
  • How can I undo my last git add/commit?
  • Git rebase from multiple branches not getting changes
  • Can/should I fork my own github repo?
  • git operations occasionally hang in Jenkins on Windows
  • Git lost change
  • how can I avoid weird git diffs like this?
  • When I commit through git, it shows java.io.IOException: An existing connection was forcibly closed by the remote host
  • Git connected to Active Directory
  • 3 Solutions collect form web for “Renaming files in git”

    This will contain the history:

    git mv backup.html backup2.html
    git mv index.html backup.html
    git mv backup2.html index.html
    

    Without history just rename the file to your liking on your file system.

    You don’t have to do anything special as you are not adding any new paths to be tracked.

    You can just move the files around and use git add to update their contents.

    mv index.html tmpname
    mv backup.html index.html
    mv tmpname backup.html
    

    then:

    git add index.html backup.html
    

    or:

    git add -u
    

    or:

    git commit -a -m "swap backup.html and index.html"
    

    Use git mv and move the first file to a temporary name, then the second to the first and finally the temporary file to the second.

    Git Baby is a git and github fan, let's start git clone.