![]() |
Git is a powerful and widely-used version control system that allows developers to track changes in their codebase, collaborate seamlessly, and maintain a robust history of their projects. It was created by Linus Torvalds in 2005, Git has become widely accepted for version control in the software development industry. In this article, we will learn how to ignore git folders and directories. .gitignore file is used to ignore the folders and directories that need to be kept private or the folders that are part of every project setup like node_modules in Nodejs project or jar files.It will ignore the folders and directories as the project is pushed to the repository. Steps to Ignore Git Folders and directories using .gitignoreFileStep 1: Initialize the Git Repositorygit init
The main purpose of the git init command is to initialize the new working environment or a new git repository to work on a new project. Before performing the git init command git will not track the files that are in the system it will start to track only when you initialize the git init command form there you can commit the files and push them to the remote repository. As we initialize the project to the repository .git folder is created. It helps to create a repository and keep track of it. ![]() .git Folder Step 2: Create a .gitignore fileIn this step, we create a .gitignore file in the project directory. .gitignore file is a text file that specifies which files and directories are ignored. Which will reduce the size of the repository. As the file is created we can add the required files and folders which are to be excluded. Syntax to exclude the folder /folder_name
Syntax to exclude the file file_name
Example: Initialize a repository on a project and push it to the Master Branch.
Steps to Removing Already Tracked FilesAlready Tracked Files are the files that are pushed in the Git repository.As git is a version control system it keeps tract of the changes in the files and folder of the repository .We can remove the file which is tracked using the following command git rm --cached file_name
Commit the changesAs the file is removed it needs to be committed to the remote repository .We use following command to commit. git commit -m "Changes"
Push the ChangesPush the changes to the remote repository . Following command is used to commit the changes git push
Example : Remove the already tracked file _styles.css![]() Remove already traced file
Why Use Git?1. Version ControlGit’s primary function is to manage changes to files over time. It allows developers to revert to previous states, track modifications, and manage multiple versions of a project without losing work. 2. CollaborationGit allows multiple developers to work on the same project simultaneously without overwriting each other’s changes. Through branches and merging, team members can contribute features and fixes while maintaining a stable codebase. 3. Backup and RestoreWith Git, every copy of the repository is a complete backup of the entire project history. This decentralized approach ensures that the loss of any single repository does not result in data loss. |
Reffered: https://www.geeksforgeeks.org
Git |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |