Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Sunday, November 8, 2015

.gitignore use case

As per last blog post

There is one more situation possible that we have to ignore something from local directory to remote directory

In attempt of finding soultion come across this soltuion

http://stackoverflow.com/questions/6147827/track-files-in-local-git-repo-but-ignore-in-remote

So the solution is

In local create another repo

For example it is code.git
Now we create javascript.git (We are not going to create local repo)
>cd /repo
>mkdir javascript.git
>cd javascript.git
>git --bare init

checkout that javascript.git inside code in local repository
#/var/www/html/code is the checkout of code.git

>cd /var/www/html/code
>git clone /repo/javascript.git javascript

Now here is an important factor
Create a file .gitignore
>cd /var/www/html/code
>vim .gitignore
/javascript
>cat .gitignore
/javascript

Now write something into javascript
>echo "Test" > javascript/test
>git commit -m "Javascript not going to commit"
#javascript not commited so in push master it is not going to push
>git push origin master
#Switch inside javascript
>cd javascript
>git commit -m "javascript will be commited"
>git push origin master

So,In this way javascript code will be commited locally but it will not sended to remote

Basic Git Setup

Note: This is my first attempt to use Git.Steps shared below is the basic setup .And i find that git local and remote repo is quite interesting feature.

|=======================|
|       Production(Code) Repo       |
|=======================|
     ||
     \/
|==============|
|   Local(Co) Repo   |
|==============|
     ||
     \/
|===================|
|        Local development    |
|===================|

As per development requirement required a setup in which
i)without copy and pasting files
ii)needed a local commit(For local backup)
iii)and when okay with the code then deploy it to the main server.

(In my case directory is in /repo)
So,First set the remote (main/master) repository(My remote repository is in some remote location
#Needed to create <name>.git
>mkdir /repo/code.git
>cd /repo/code.git
>git --bare init

In local repository
>mkdir /repo/co.git
>cd /repo/co.git
>git --bare init
>git remote add origin ssh://<name>@<host>/repo/code.git

Development code
>cd /var/www
>git clone /repo/co.git co
>cd co
>git pull origin master

Now in development code
>cd /var/www/co
>echo "abc" > test
>git add test
>git commit -m "First commit"
>git push origin master

If you have to check the local commit works or not
>mkdir /var/www/co1
>cd /var/www
>git clone /repo/co.git co1
>cd co1
>git pull origin master

#---You will see the file there means
Now send this commit to main directory
>cd /repo/co.git
>git push origin master
#---If key based authenticaiton not there then it will ask for password

Now after that you can just pull remote server directory anywhere.So,Local repo is the local repository where you can commit any time and can pull from remote server and can accept push from local directory.