Thursday, 20 August 2015

Some Git Stuffs --How to Clone, Commit, Push, Config, Change username, email, email per repository

How to clone, commit, push git repository
If you are working with Git and want to edit any files in git repository, then you need to follow the following steps
Go to the local directory where you wants to copy the git repo.
$ cd directory
$ git clone <repo> 
$ git clone <repo> <directory>
Clone the repository located at <repo> into the folder called <directory> on the local machine.
To update the git repository
$ git pull
How to recursively add the files in  directory

Go to the directory where your files are located.
$ cd directory
$ mkdir -p /dir1/dir2/dir3/dir4/
$ touch new file
$ git add *
Now you must commit these changes (You can give necessary comments)
$ git commit -m "Adding new files"
If you want to add a directory and all the files which are located inside it recursively, Go to the directory where the directory you want to add is located.
$ cd directory
$ git add directoryname
Now you must commit these changes (You can give necessary comments)
$ git commit -m "Adding a new directory"
Note that the above step will commit recursively the subdirectories and files present in the directory.
Finally push the  changes to git server repo
$ git push -u origin master
How do I show or change my Git username (or email address)?

There are several ways to show your Git username

git config user.name

You can also use

 git config --list

which returns this output:

user.name=GitLab
user.email=(none)
core.autocrlf=input

Finally, you can also see your Git username in the Git configuration file in your HOME directory on Unix systems, i.e., this file:

~/.gitconfig

How to change your Git email address

git config user.email

And you can change your Git email address like this:

git config --global user.email [your email address here]

Set git email address on a per repository basis

Keeping global email address for all repositories is not a good idea, especially if
there are multiple users using the same or repositories.
Git allows you to specify email addresses on a per repository basis. This is
handy when working with repositories from different environment
Set the global user email as below
email = "(none)"
When in the repo directory, use the following commands to set a per repository email address:
adixit@hostname:~/git$ git config user.name “amit dixit”
adixit@hostname:~/git$ git config user.email “some@gittestdomain.com”
Alternatively, you can edit .git/config manually, and add the required information under the [user] heading:
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = https://adixit@git.dev.somedomain.com/repo/gitrepo/new.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        email = some@gittestdomain.com
The benefit of keeping global email as none is that if anytime you forget to change the user email per repository and once you try to commit, you’ll get the following error message:
*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got '(none)')

Wednesday, 14 August 2013


KILL REMOTE SSH SESSIONS

Do a w command to get the tty details of the session that you would like to terminate.

$ w
username pts/4 :0.0 12:35 1:13m 0.19s 24.44s gnome-terminal
username pts/6 :0.0 11:28 1:15m 0.43s 24.44s gnome-terminal
root pts/2 192.168.0.XX 16:26 0.00s 0.02s 0.00s w

In the above example, i have initiated another ssh session from 192.168.0.XX. To kill this session,
Find the PID of the process with

$ ps -ft pts/2
11236

$ kill -9 11236

This will terminate the remote session.

Monday, 29 July 2013

Setup SVN And Access Through SVN Protocol on Debian Wheezy


Installing Subversion

Subversion can be installed as follows:

apt-get install subversion


Next we create a directory that will hold our repository/repositories - I use /var/lib/svn, but you can use another directory, if you like.

mkdir -p /var/lib/svn

I want to create a repository for my software project called myproject inside the /var/lib/svn directory  this can be done as follows:

svnadmin create /var/lib/svn/myproject

Using The svn:// Protocol


We can use the svn:// protocol by starting the svnserve daemon.
Before we do this, let's configure password protection for our repository. There's a conf/svnserve.conf file in each repository, so for /var/lib/svn/myproject it's/var/lib/svn/myproject/conf/svnserve.conf. open that file...

vim /var/lib/svn/myproject/conf/svnserve.conf
Then add the following entries to /var/lib/svn/myproject/conf/svnserve.conf file:

anon-access = none
auth-access = write
password-db = passwd
realm = My SVN Repository

Now add an svn user by adding following entry to /var/lib/svn/myproject/conf/svnserve.conf file:
amit = amitpw

Now time to start the SVN Serve Daemon:
svnserve -d -r /var/lib/svn
(The -d switch makes it run as a daemon in the background.)
Run 
netstat -tap | grep svn
tcp        0      0 *:svn             *:*                     LISTEN      12766/svnserve


Now we can use the svn:// protocol. For example, a checkout can be done as follows:

svn co --username amit svn://192.168.0.100/myproject /home/amit/somedir

 Using The svn+ssh:// Protocol



To tunnel the svn:// protocol through SSH, just follow chapter 6 and make sure you have an SSH damon running on your Debian system (if you have not, you can install it by running:

apt-get install openssh-server ssh

That's it! All you have to do now is to use svn+ssh:// instead of svn://, for example, a checkout can be done as follows:

svn co --username amit svn+ssh://192.168.0.100/var/lib/svn/myproject /home/falko/somedir



Friday, 26 July 2013

Migration Of Git Repo From One Server To Another

Linux distribution like Debian. First, you create a 'git' user. 

$ adduser git $ su git $ cd


Now, you can set up an empty repository for them by running git init with the --bare option, which initializes the repository without a working directory:
$ cd /home/git
$ mkdir project.git
$ cd project.git
$ git --bare init

Here is how to move your GIT repository from one server to another. In my case I needed to move from Old-server to a New-server.


On New-server : 

$ mkdir tempgit
$ cd tempgit
$ git clone --bare git@Old_Git_Server:Old-Repo.git
$ cd Old-Repo.git
$ git push --mirror git@New_Git_Server:New-Repo.git
$ cd ..
$ rm -rf {REPOSITORY_NAME}.git

On Client Side: 

$ git clone git@:New_Git_Server:New-Repo.git
$ cd project
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master









Debian / Ubuntu Linux Install NTPD To Synchronism Clock With Internet Standard Time Servers

Ntpd is an operating system daemon which sets and maintains the system time-of-day in synchronism with Internet standard time servers. Ntpd is a complete implementation of the Network Time Protocol (NTP) version 4 but also retains compatibility with version 3.

Install ntp server

Type the following command:
# apt-get install ntp
Sample output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libcap1
Suggested packages:
  ntp-doc
The following NEW packages will be installed:
  libcap1 ntp
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 443kB of archives.
After this operation, 1126kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.us.debian.org lenny/main libcap1 1:1.10-14 [9082B]
Get:2 http://ftp.us.debian.org lenny/main ntp 1:4.2.4p4+dfsg-7 [434kB]
Fetched 443kB in 0s (480kB/s)
Selecting previously deselected package libcap1.
(Reading database ... 20411 files and directories currently installed.)
Unpacking libcap1 (from .../libcap1_1%3a1.10-14_i386.deb) ...
Selecting previously deselected package ntp.
Unpacking ntp (from .../ntp_1%3a4.2.4p4+dfsg-7_i386.deb) ...
Processing triggers for man-db ...
Setting up libcap1 (1:1.10-14) ...
Setting up ntp (1:4.2.4p4+dfsg-7) ...
Starting NTP server: ntpd.

Configure NTP server

/etc/ntp.conf is default configuration file. NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency by using a jitter buffer.
# vi /etc/ntp.conf
The default configuration will sync to various low-stratum NTP servers. You can set server as follows:
server 0.debian.pool.ntp.org iburst dynamic
server 1.debian.pool.ntp.org iburst dynamic
server 2.debian.pool.ntp.org iburst dynamic
server 3.debian.pool.ntp.org iburst dynamic
Once file updaed, restart ntp:
# /etc/init.d/ntp restart

ntpq - NTP query program

You can use ntpq to list the servers that you are currently polling:
$ ntpq
Sample output:
ntpq> peer
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.nist.gov   .ACTS.           1 u  128   64  376   64.616   -8.079   0.863
+iguana.igtc.com 198.60.22.240    2 u   19   64  377    9.105   -9.229   0.543
+hydrogen.cert.u 216.218.254.202  2 u   12   64  377   35.950   -7.184   0.438
-snag.rack911.co 66.90.104.142    3 u   50   64  377   33.782   -0.376   0.464
Alternatively, you can type the following to find out if ntp is working or not:
$ ntpq -p
Sample output:
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.nist.gov   .ACTS.           1 u    3   64  373   64.616   -8.079   0.716
+iguana.igtc.com 198.60.22.240    2 u   28   64  377    9.065   -9.429   0.628
+hydrogen.cert.u 216.218.254.202  2 u   19   64  377   35.950   -7.184   0.357
-snag.rack911.co 66.90.104.142    3 u   57   64  377   33.695   -0.893   0.645


INSTALLING JAVA 7 ON DEBIAN SQUEEZE


For all of my servers I use Debian, however that distribution has a few problems, mainly the packages can be a bit behind the cutting edge.
Now this is usually a good thing if you are looking for stability – cutting edge software can have issues, especially from new features etc, so for a live environment you want something thats stable.
However, there does come a time when this can bite back. You either need a feature thats not in the standard repositories or in this case the version is now unsupported.
In Debian Squeeze it has Java 6 – but that was EOL’d a couple of months ago so is no longer supported by Oracle. The current version is Java 7 update 17.
So how do we get Java 7 installed?
Well it’s pretty easy to do, we just need to add another repository into apt and install it.
First the repository:
1
2
3
4
5
6
sudo su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update


What that does is to install the ubuntu ppa repository into apt, setup the public keys and then load the package lists.
Next we need to install it:
1
sudo apt-get install oracle-java7-installer
This will now download Oracle Java 7 and present you with a couple of screens about licensing. Just ok and accept it and it will now install.
That’s it. You now have Java 7 installed – but it’s not the default JDK (if you already had Java 6 installed). If you want it to be the default then there’s just one more thing to do:
1
sudo apt-get install oracle-java7-set-default
That’s a dummy package but it will make Java 7 the default on that machine. If you want to check then you can check:
1
2
3
4
peter@titan ~ $ java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)