Last active
February 24, 2016 04:32
-
-
Save kittolau/8a7c362dc9a7a7c8dbcb to your computer and use it in GitHub Desktop.
git cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#============================ | |
#Create bare git repo for deployment | |
#============================ | |
mkdir -p ~/repo/application_stage.git && cd ~/repo/application_stage.git | |
git --bare init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#list branch | |
git branch | |
#list branch with upstream | |
git branch -vv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
git clone file:///home/myuser/repo/application_stage.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git remote set-url origin <new url> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git rm --cached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#stage all files | |
git add -A | |
#check which file is staged | |
git status | |
#commit | |
git commit -m "init commit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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