'git mv' command is used to rename
or move a file, directory.
Syntax
git mv {current_file_name} {new_file_name}
Step 1: Clone a repository by executing below command.
git clone {repository_url}
$git clone https://github.com/harikrishna553/gitHelloWorld.git Cloning into 'gitHelloWorld'... remote: Enumerating objects: 24, done. remote: Counting objects: 100% (24/24), done. remote: Compressing objects: 100% (17/17), done. remote: Total 24 (delta 3), reused 14 (delta 1), pack-reused 0 Unpacking objects: 100% (24/24), done.
Folder structure looks like
below.
$tree . └── gitHelloWorld ├── README.md ├── tempFile1.txt ├── tempFile4.txt └── welcome.txt 1 directory, 4 files
Step 2: Navigate to gitHelloWorld directory and rename the file tempFile4.txt to
tempFile4_copy.txt using ‘git mv’ command.
$cd gitHelloWorld/ $ $git mv tempFile4.txt tempFile4_copy.txt $ $tree . ├── README.md ├── tempFile1.txt ├── tempFile4_copy.txt └── welcome.txt 0 directories, 4 files $ $git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: tempFile4.txt -> tempFile4_copy.txt
Step 3: Commit the changes.
$git commit -m "Renamed tempFile4.txt to tempFile4_copy.txt" [master 3f857de] Renamed tempFile4.txt to tempFile4_copy.txt 1 file changed, 0 insertions(+), 0 deletions(-) rename tempFile4.txt => tempFile4_copy.txt (100%)
Step 4: Push the changes to remote branch.
Before pushing the changes.
$git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 12 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 261 bytes | 261.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/harikrishna553/gitHelloWorld.git 4f26ba8..3f857de master -> master
After pushing the changes.
No comments:
Post a Comment