Git - Rename the File and Push

Once you moved the code to Git, you realized as some of the files named incorrectly. Git provided a command to rename the file easily.

Let’s rename about.html file to about-us.html file. First, remove the about.html file, then add the about-us.html file. 

c:\Examples\techExamples>git rm about.html  (it removes the about.html file)

c:\Examples\techExamples>git add about-us.html (it adds new file about-us.html)

Finally, commit the changes and push to Git server repository. 

c:\Examples\techExamples>git commit -m "Rename about.html to about-us.html"

[master 17b8748] Rename about.html to about-us.html

 2 files changed, 8 insertions(+), 8 deletions(-)

 create mode 100644 about-us.html

 delete mode 100644 about.html 

c:\Examples\techExamples>git log

commit 17b87483928f10e1492c655ea952a805f7e68846 (HEAD -> master)

Author: Raj <xxx.xxxx@hotmail.com>

Date:   Tue May 14 22:37:32 2019 +0100 

    Rename about.html to about-us.html 

commit cb15ab442e3ec6eb6c281d3a0586414258533871 (origin/master, origin/HEAD)

Author: Raj <xxx.xxxx@hotmail.com>

Date:   Mon May 13 21:25:06 2019 +0100 

    'AddedContentFile' 

commit 3c13ce05a103a9108bd911b6f4b5e8829127334c

Author: Raj <xxx.xxxx@hotmail.com>

Date:   Sun May 12 15:33:11 2019 +0100 

    'AddTwoFiles' 

commit 32ce97686389177d9ee7782767a77735e11ee391

Author: Raj <xxx.xxxx@hotmail.com>

Date:   Sun May 12 01:00:08 2019 +0100 

    'InitialChanges' 

c:\Examples\techExamples>git push https://dev.azure.com/vsotech/_git/techExamples

Enumerating objects: 3, done.

Counting objects: 100% (3/3), done.

Delta compression using up to 4 threads

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 316 bytes | 24.00 KiB/s, done.

Total 2 (delta 0), reused 0 (delta 0)

remote: Analyzing objects... (2/2) (80 ms)

remote: Storing packfile... done (80 ms)

remote: Storing index... done (44 ms)

To https://dev.azure.com/vsotech/_git/techExamples

   cb15ab4..17b8748  master -> master 

c:\Examples\techExamples>