Git Ignore All Except Some Files

If you already have a .gitignore file with rules, you can change them.


My .gitignore looked like this;

#ignore these folders
scripts/
lib/**
logs/

# ignore these files
.sql 

Let's say you now want to include a file located at /lib/config.php. You would add this line;

#ignore these folders
scripts/
lib/**
logs/

# ignore these files
.sql

# allow
!lib/config.php 

Next run git status and you should see ;


untracked files 

/lib


Now you can run git add lib/ 


After another git status you should see;


new file:  lib/config.php

modified: .gitignore


Then add both files git add . 


From here you can commit and push to the remote repo.



MySQL Check All Tables in Database
MySQL Repair All Tables in Database
 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Guest
February 26, 2020

Captcha Image

Latest Comments

Guest - Susan Hermiston Virtual Hosts
October 7, 2015
Wow 747 just blew me away. Sorry not a tech person at all!! But I still love you!! Rock on!!?
Guest - Johmny Invisible Mouse Cursor Ubuntu & Synergy
September 2, 2015
Glad I was ble to help!
Guest - Kristian Falk Invisible Mouse Cursor Ubuntu & Synergy
September 1, 2015
Thank you for this! Had the exact same problem. I almost went crazy.