Thursday 22 May 2014

GIT - ignore committing list of unnecessary files ( using .git/info/exclude )

If you are using GIT for version control, there is way you can ignore committing unnecessary files as per required.
Step 1. And to do that, please open a project_folder/.git/info/exclude file then update the file as per below example;
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

# Your Main Application files (Example for CodeIgniter based application) #
######################
/.idea/*
/assets/_upload/_articles/* // * mean exclude all the files
/assets/_upload/_tmp/*

!/assets/_upload/_articles/index.html // ! mean not exclude this file
!/assets/_upload/_tmp/index.html

/application/config/config.php 
/application/config/database.php 

/application/cache/*
/application/cache/templates_compiled/*
/application/CachedWebContent/*
/application/logs/*

/error_log

Basic exclude rules for CodeIgniter based application as below; if you like you can modify them as per your needs.

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
 
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
 
# Logs and databases #
######################
*.log
*.sql
*.sqlite
 
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Step 2. Edit the file and Save it.
Step 3. Then clean the previous cached rules if any. Run below code each time you modified the exclude file

# git reset HEAD

Step 4.

# git add -- all // Add all the new folders or files if you have added any
# git commit -am "You comments for commit"
# git push
#
That's all you need to know! Enjoy!!!

Git Clone local repository to another repository, Exclude some folder

// Git Clone local repository to another repository
// -----------------------------------------------
$ mkdir c/xampp/htdocs/repo1 // create repository one
$ cd c/xampp/htdocs/repo1 // Go into folder
$ git init // initialise the git
$ git add -all // All all the file and folder

// To clone all the files except particular folders
// -----------------------------------------------
$ git reset -- folder1/ folder2/ // Exclude the folder1, folder2 from committing


// To clone to another local directory 
// -----------------------------------------------
$ git clone path_to_repository1/ path_to_another_repository/

$ git pull // To pull the updates from repo1.