‘git rm’ command remove files
from working tree and from the index.
Syntax
git rm {file_name}
Step 1: Clone the repository using below command.
git clone {repository_name}
$git clone https://github.com/harikrishna553/gitHelloWorld.git Cloning into 'gitHelloWorld'... remote: Enumerating objects: 20, done. remote: Counting objects: 100% (20/20), done. remote: Compressing objects: 100% (14/14), done. remote: Total 20 (delta 0), reused 11 (delta 0), pack-reused 0 Unpacking objects: 100% (20/20), done. $ $tree . └── gitHelloWorld ├── README.md ├── tempFile1.txt ├── tempFile2.txt ├── tempFile3.txt ├── tempFile4.txt └── welcome.txt 1 directory, 6 files
Step 2: Navigate to ‘gitHelloWorld’ folder and remove tempFile3.txt.
$cd gitHelloWorld/ $ $git rm tempFile3.txt rm 'tempFile3.txt' $ $tree . ├── README.md ├── tempFile1.txt ├── tempFile2.txt ├── tempFile4.txt └── welcome.txt 0 directories, 5 files
Step 3: Execute ‘git status’ command.
$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) deleted: tempFile3.txt
Step 4: Commit and push the changes
Before committing the changes.
Execute below commands to
commit and push the changes to master.
git commit -m "Deleting
tempFile3.txt"
git push origin master
$git commit -m "Deleting tempFile3.txt" [master 3d2911a] Deleting tempFile3.txt 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tempFile3.txt $ $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), 245 bytes | 245.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 c935e35..3d2911a master -> master
Once you commit and push the
change to remote repository, you can see that ‘tempFile3.txt’ is removed in
remote repository.
No comments:
Post a Comment