Skip to main content

Github : ignore files


Recently I have started working with git version control system and I’m loving it, especially the Git bash. 

Usually in each and every project there are some files which we don’t want to commit and push on live again and again. For example configuration files and db files once committed don’t need to be modify again for live site. In such cases to stop manual intervention git provide us the facility to ignore files.

Let’s discuss:  

We can ignore files in two ways.

1) Using .gitignore file : 

If you don’t want some files to be added and want to ignore them while uploading on 
server, then you can use .gitignore file. For example you have a file named
bkp_config.php and while pushing you code live you don’t want to push that file.
In such cases you can use .gitignore file.  

There are again two scenarios.

a)     Files have already been tracked.

Means first you have added the files, committed them and then pushed them on master repository. 

Like :

$ git add .

$ git commit -m 'Pushed Code live' 

$ git push origin master
After some time you realized that you shouldn’t have done that. Then you added .gitignore file so that in future git can ignore this file to be committed. 

.gitignore file

//content of .gitignore file 
bkp_config.php

It will use its rules when looking at files to commit. Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with 

git rm --cached < filename >

So in this case we have to un-track the file first.

Run 

$ git rm --cached 'bkp_config.php'

$ git add .


$ git commit –m ‘message’

$ git push origin master

(when you will commit changes and will push on server and other users have pulled the data then the file will get deleted from their clones request as well.)

Now your files are in un-tracked stage. Now go to point (b).

This file(.gitignore) can be committed into the repository, thus sharing the rule list with any other users that clone the repository.

Note that you can create a .gitignore in any subpath to have its rules applied at that path. Sometimes an empty .gitignore file is used as a placeholder for an empty path, for example to force git to generate a log/ path for your development environment to use.


b)     Files are un-tracked. 

In this case just add the rule in .gitignore file and commit the file. Push it.

If you want to even stop adding .gitignore file then use 

$ echo .gitignore >> .gitignore.

So .gitignore  file will also become un-tracked.

Next time when you will run git add . command ignored files will not get added.

2) Ignore Versioned Files :

There are some files like db.config or config.php which includes different data for local and live server. So such files are once added to the live server and after that we rarely need those to be changed and they would have different data on both local and live files. In that case we can use following command so that whenever we make any changes in local config files we should’t commit it knowingly or mistakenly.  Use

$ git update-index --assume-unchanged <file> 

If you will make any changes in a file then it would not appear in git status list. So will not get added and committed. 

List all files marked as --assume-unchanged

$ git ls-files -v | grep ^[a-z]

If you want to start tracking changes again run the following command:

$ git update-index --no-assume-unchanged <file>  


That's it. Please send me your valuable feedback through comments. All type of suggestions are welcome.

Thanks!!!!!!!!! Enjoy Programming :)

 

Comments

Popular posts from this blog

Odoo/OpenERP: one2one relational field example

one2one relational field is deprecated in OpenERP version>5 but you can achieve the same using many2one relational field. You can achieve it in following two ways : 1) using many2one field in both the objects ( http://tutorialopenerp.wordpress.com/2014/04/23/one2one/ ) 2)  using inheritance by deligation You can easily find the first solution with little search over internet so let's start with 2nd solution. Scenario :  I want to create a one2one relation between two objects of openerp hr.employee and hr.employee.medical.details What I should do  i. Add _inherits section in hr_employee class ii. Add field medical_detail_id in hr_employee class class hr_employee(osv.osv):     _name = 'hr.employee'     _inherits = {' hr.employee.medical.details ': "medical_detail_id"}     _inherit = 'hr.employee'         _columns = {              'emp_code':fields.char('Employee Code', si

How to draw Dynamic Line or Timeseries Chart in Java using jfreechart library?

Today we are going to write a code to draw a dynamic timeseries-cum-line chart in java.   The only difference between simple and dynamic chart is that a dynamic event is used to create a new series and update the graph. In out example we are using timer which automatically calls a funtion after every 1/4 th second and graph is updated with random data. Let's try with the code : Note : I had tried my best to provide complete documentation along with code. If at any time anyone have any doubt or question please post in comments section. DynamicLineAndTimeSeriesChart.java import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import

pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]

Recently, I faced this error in our Docker-Container environment. All the necessary packages were already installed but still, I was facing this clueless error. I search a bit and after an hour and so I found the exact reason and solution for this error. To know more about this error in detail. Please follow this Github thread. https://github.com/mkleehammer/pyodbc/issues/610 https://github.com/mkleehammer/pyodbc/issues/610#issuecomment-587523802 Solution: It's because the   server's certificate has too weak a key. In case you are using Linux env directly/not the Docker one.  Just edited /etc/ssl/openssl.cnf and change these 2 lines. MinProtocol = TLSv1.0 CipherString = DEFAULT@SECLEVEL=1 In case you are also using a container, please add these three lines to your Docker file. RUN chmod +rwx /etc/ssl/openssl.cnf RUN sed -i ' s/TLSv1.2/TLSv1/g ' /etc/ssl/openssl.cnf RUN sed -i ' s/SECLEVEL=2/SECLEVEL=1/g ' /etc/ssl/openssl.cnf Thanks!! Enjoy Programming! Refer