Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does gitignore work?

Tags:

git

Hello I'm new to git and I can't fully understand the .gitignore.

So let's say I have a Master Folder currently in Production and inside it there's a reports folder that I don't really need to track.

Master Folder
 |
 +-- file 1
 |    
 +-- dir 2
 |  |  
 |  \-- file 2.1
 |    
 +-- dir 3
 |  |  
 |  +-- file 3.1
 |  \-- file 3.2
 |    
 +-- Reports
 |  |  
 |  +-- file 4.1
 |  \-- file 4.2

Now, I wanted to modify the folder so I clone the Master Folder in my repository. Does the reports folder gets cloned too?

While I'm editing, some person added or changed files inside the reports folder.

After I finish editing, I need to update the Master Folder to what I've updated. If I git push my changes, will it affect the Reports Folder in the Master Folder?

like image 576
Kay Singian Avatar asked Jul 18 '17 06:07

Kay Singian


People also ask

How does the Gitignore works?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Does Gitignore work automatically?

gitignore is an auto-generated file inside the project folder that ignores/prevents files to get committed to the local and remote repositories.

What do you use Gitignore for?

You can create a .gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the .gitignore file in to your repository.


1 Answers

Before you commit the reports to master, make sure you create a new .gitignore file in the root of your project. Once this is done, include the paths of the folders or files to the gitignore file. Make sure you specify one path per line.

In your case, if you want to ignore all the files in your Reports folder, then add the following to the .gitignore file.

/Reports

If you want to exclude specific files, you can do something like

/Reports/*.docx

Assuming thst the reports are mixed file extensions but you want to ignore all word file reports from the folder.

About cloning, if someone tries to clone the project, he won't get any report files as they were not committed at first place. Also, making any changes in the Reports folder won't be tracked by git any more.

like image 188
Mr. Alien Avatar answered Oct 29 '22 19:10

Mr. Alien