Skip to content

Instantly share code, notes, and snippets.

@kittolau
Last active February 24, 2016 04:32
Show Gist options
  • Save kittolau/8a7c362dc9a7a7c8dbcb to your computer and use it in GitHub Desktop.
Save kittolau/8a7c362dc9a7a7c8dbcb to your computer and use it in GitHub Desktop.
git cheat sheet
#!/bin/sh
#============================
#Create bare git repo for deployment
#============================
mkdir -p ~/repo/application_stage.git && cd ~/repo/application_stage.git
git --bare init
#list branch
git branch
#list branch with upstream
git branch -vv
#!/bin/sh
git clone file:///home/myuser/repo/application_stage.git
#!/bin/sh
#============================
APP_NAME=myApp
#============================
#add a remote branch(defined as origin) via SSH with the path of bare repo($APP_NAME.git is a folder)
git remote add origin vagrant@127.0.0.1:/var/deploy/$APP_NAME.git
#list all remote branch
git remote -v
#push to remote branch(origin) from local branch(master)
# -u: setting master as upstream
git push -u origin master
#remove a remote branch(origin)
#git remote rm origin
#!/bin/sh
#============================
#Git Key Auth
HOST=production-server
HOST_DOMAIN_NAME=git.company.com
USER=deploy
PRIVATE_KEY=~/.ssh/id_rsa.deploy
APPLICATION=myApp
STAGE=produciion
REMOTE_BRANCH_NAME=alice
#============================
if [ -e ~/.ssh/config ]
then
echo "SSH config found."
else
echo "SSH config not found. create a new one..."
touch ~/.ssh/config
fi
echo "Host $HOST" >> ~/.ssh/config
echo " HostName $HOST_DOMAIN_NAME" >> ~/.ssh/config
echo " User $USER" >> ~/.ssh/config
echo " IdentityFile $PRIVATE_KEY" >> ~/.ssh/config
echo " IdentitiesOnly yes" >> ~/.ssh/config
git remote add ${REMOTE_BRANCH_NAME} ${USER}@$HOST:/home/${USER}/apps/${APPLICATION}_${STAGE}.git
#!/bin/sh
#============================
#Git Password auth
APPLICATION=helpAround
STAGE=production
DEPLOY_USER=deploy
PRODUCTION_SERVER_IP=127.0.0.1
#============================
git remote add $STAGE ${DEPLOY_USER}@${PRODUCTION_SERVER_IP}:/home/${DEPLOY_USER}/repo/${APPLICATION}_${STAGE}.git
git checkout -b production
git push -u $STAGE production
#list all remote branch
git remote -v
git remote set-url origin <new url>
#stage all files
git add -A
#check which file is staged
git status
#commit
git commit -m "init commit"
#Also see
# http://programmers.stackexchange.com/questions/141973/how-do-you-achieve-a-numeric-versioning-scheme-with-git
# use tag name as v1.0
# v2.5-0-deadbeef
# ^ ^ ^
# | | |
# | | SHA of HEAD
# | |
# | number of commits since last tag
# |
# last tag
git describe --long --tags --dirty --always
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment