Git Commands and Usage

Git Add and Remove Files: File Operations Explained

Learn how to add, remove, rename, copy, and commit files in Git. These commands help you manage project changes safely and keep your repository clean.

Serhat ALPASLAN3 min read

Contents

 

Git Add File, Git Delete File, and Git Update Operations

Git is a version control system that tracks data and projects and monitors their versions. Basic operations such as adding, deleting, and updating files with Git let you manage projects effectively. git add adds files, git rm deletes files, and git commit updates files. These concepts make project version control easier.

Git Add (Adding a File)

If you want to add one file or all files to the index, you should use it as follows.

git add "dosya.txt"
// dosya.txt is added to the stage / index and made ready for commit 
git add dosya.txt dosya2.txt dosya3.txt
// with this syntax, we added our files to the git stage / index.

In the example above, when the command is run, the file is added to the stage. You can think of the stage as an intermediate layer. The information added here waits for the commit operation, and then we can send it to our repository.

If you want to add all files

git add .
// with the trailing dot, we told Git to add all files to the index and made them ready for commit.

Git Commit (Take and Save a Snapshot)

It takes and saves a snapshot of any change you make with Git. Adding a message / note while performing the commit is a very good idea so that you can understand the changes you made after a while.

git commit –m “commit test”

Git Rm (Deleting a File)

When you want to delete a file that has been added, you can use it as follows.

git rm "dosya.txt"

Git Mv (Renaming a File or Folder)

Sometimes we may name files or folders incorrectly for one reason or another. In this case, we can fix it by using the following command.

Git mv eski.txt yeni.txt

Git Cp (Copying a File or Folder)

The Git cp command lets you copy a file or folder in your Git database to another location. This command makes it possible to reuse your file or folder under a different name or move it to a different place. The Git cp command is similar to the cp command used on Unix and Linux systems, and while using it, you will need to specify the path of the files and folders in the Git database.
cp metin.txt yenimetin.txt

Share it if it helped

Write a comment