Find us on facebook

Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Jan 31, 2018

Restrict ssh to git

 cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/tmux
/usr/bin/screen
 
$ which git-shell
/usr/bin/git-shell
 
$ sudo nano /etc/shells (add  /usr/bin/git-shell)
$ sudo chsh git -s /usr/bin/git-shell

setup git server

su -
sudo useradd git
  === Enter new UNIX password:
  === Retype new UNIX password:
  === passwd: password updated successfully

 sudo apt-get install git
 
 su git
 sudo mkdir git (create git folder on home)
 move id_rsa.pub to /home/git
 mkdir ~/.ssh && chmod 700 ~/.ssh
 touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
 
 cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
 cat ~/.ssh/authorized_keys

 mkdir project.git
 cd project.git
 git init --bare

On git push , publish files to live

git init --bare
cd project.git
cd hooks

cat > post-receive

#!/bin/sh
git --work-tree=/var/www/html/project --git-dir=/home/ishara/git/project.git checkout -f

CTRL+D to exit

chmod +x post-receive
 

When deploying files, you need to give permission to /var/www/html/project 
add system user group permission to /var/www/html/project using following command.

chown -R user:group projectfolder
 

In local git repo add remote
 
local .git/config
[remote "live"]
        url = ssh://ishara@111.111.11.11/home/ishara/git/project.git
        fetch = +refs/heads/*:refs/remotes/live/*
[remote "repo"]
        url = git@222.222.22.222:project.git
        fetch = +refs/heads/*:refs/remotes/repo/*

 
push command from local machine
git push live master (deploy live)
git push repo master (deploy to git server repo)
 

Git - Slack integration

  • cd to your bare repo eg:project.git and cd to hooks and create post-receive hook
  • Add bash commands to push related information to slack. (You can find many bash scripts published in the internet or you can write your own script referring following parameters in the post-receive hook.
    oldrev
    newrev
    refname
  • Give permission 
chmod +x post-receive
  • cd to your bare repo eg:project.git and execute following commands
git config -f config hooks.slack.webhook-url 'https://hooks.slack.com/services/xxx.....'

git config hooks.slack.channel '#development-xxx'

Jun 2, 2015

Get latest from Git Master to other branch

git fetch origin
git checkout master
git merge origin/master

To switch to your branch, just do
git checkout branch1

Merge a git branch into master

git checkout master
git pull origin master
git merge test(branch name)
git push origin master

Adding an existing project to GitHub

Initialize the local directory as a Git repository.
git init

Add the files in your new local repository. This stages them for the first commit.
git add .

Commit the files that you've staged in your local repository.
git commit -m 'First commit'

In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
git remote add origin https://ishara@bitbucket.org/ishara/weatherapp.git
# Sets the new remote
git remote -v
# Verifies the new remote URL

GitHub for Windows users should use the command git remote set-url origin instead of git remote add origin here.

git push origin master

Install Git on Ubuntu

sudo apt-get update
sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
wget https://github.com/git/git/archive/v1.9.2.zip -O git.zip (You can get latest version from git)
unzip git.zip
cd git-*
make prefix=/usr/local all
sudo make prefix=/usr/local install

if you want to upgrade to a later version, you can simply clone the repository and then build and install:
git clone https://github.com/git/git.git

Following commands will rebuild and reinstall the package
make prefix=/usr/local all
sudo make prefix=/usr/local install

git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"

May 13, 2015

Commiting and Pushing in Git

git add <path/filename> OR git add *
git commit -m "Worldpay changed view"
git push origin master


Install Git in CentOS server

yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel
cd /usr/local/src
wget https://www.kernel.org/pub/software/scm/git/git-1.8.2.3.tar.gz
tar xzvf git-1.8.2.3.tar.gz
cd git-1.8.2.3
make prefix=/usr/local all
make prefix=/usr/local install