git config --global user.name "k2patel" git config --global user.email "k2patel@live.com"
<note tip>replace location with your desired location</note>
mkdir -p /data/git/bumper.git cd /data/git/bumper.git
git --bare init
<note tip>replace project location with desired location</note>
cd /data/project/bumper/ git init git add . git commit -m "Initial Commit"
For Local
git remote add origin /data/git/bumper.git git push origin master
For Remote
git remote add origin ketan@reposerver:/data/git/bumper.git git push origin master
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.
git remote -v
cd $HOME git --bare init --shared test.git
after you taste your login.
cd ~/test.git git remote add backup --mirror git@backup.k2patel.com:test.git git push backup cat .git/config
Result of last line should should contain text like the next block.
# [remote "Backup"] # url = git@backup.k2patel.com:test.git # fetch = +refs/*:refs/* # mirror = true
#!/bin/bash #Build by. kpatel # k2patel@hotmail.com ## Nightly Backup of Repository. ## Variables -- ( change According to your need ) repohome=(/home/backup/test.git /home/backup/test2.git ) export receipients="k2patel@sify.com k2patel@hotmail.com" ## 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
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 reset --hard origin/master git pull
git clone --recursive git@github.com:k2patel/repo.git
git submodule update --init --recursive
git submodule update --init modules/repo
git submodule foreach git pull origin master
git submodule update --init