GIT Repository¶
Setting up GIT¶
Create Server¶
Define User¶
git config --global user.name "k2patel"
git config --global user.email "[email protected]"
Create location for Repository¶
Tip: replace location with your desired location
Create bare repository¶
Initial Synchronize with client¶
Initializing commit¶
Tip: replace project location with desired location
Define server and push files¶
For Local
For Remote
Backup¶
To do backup on existing git repo please follow steps below.
Login to master machine.
Considering you already have key based access between master and backup server.
list available remote repository on master¶
Now create bare repo on backup server¶
On Master Server¶
after you taste your login.
cd ~/test.git
git remote add backup --mirror [email protected]:test.git
git push backup
cat .git/config
Result of last line should should contain text like the next block.
# [remote "Backup"]
# url = [email protected]:test.git
# fetch = +refs/*:refs/*
# mirror = true
Script for Backup¶
#!/bin/bash
#Build by. kpatel
# [email protected]
## Nightly Backup of Repository.
## Variables -- ( change According to your need )
repohome=(/home/backup/test.git /home/backup/test2.git )
export receipients="[email protected] [email protected]"
## Static
export git=$(which git)
## Methods
notify(){
for n in $receipients; do
echo $1 | /bin/mail -s "[GIT] Backup $k2 Failed" $n
done
}
## Programm
for k2 in ${repohome[@]}; do
echo $k2
if cd $k2 && $git push backup ; then
echo "done"
else
notify "GIT Backup Failed, $k2"
fi
done
Git reset local¶
following command can be used for following purpose :
To discard all local changes and restore it to the remote repository.
When you have error Your branch is ahead of 'origin/master'
Git Submodule¶
Clone Repository including submodule¶
git clone --recursive [email protected]:k2patel/repo.git