Created
October 20, 2018 16:31
-
-
Save ethanj/7765294c76ec5db05c62f3fd83ef9163 to your computer and use it in GitHub Desktop.
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
github ethanj 5El5R5IBfN1s | |
# install hub for extra git commands for github | |
# https://hub.github.com/hub.1.html | |
brew install hub && echo "\n#add github commands to git\neval \"\$(hub alias -s)\"" >> ~/.zshrc | |
# create a new private repo and setup remote | |
git create -p philosophie/foo | |
git remote add origin [email protected]:philosophie/foo.git | |
git push -u origin master | |
--- | |
aliases in ~/.gitconfig: | |
[alias] | |
co = checkout | |
ci = commit | |
st = status | |
br = branch | |
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short | |
type = cat-file -t | |
dump = cat-file -p | |
---- | |
#cache passwords | |
git config --global credential.helper cache | |
#adds the following to .gitconfig: | |
#[credential] | |
# helper = cache | |
#nice reference | |
http://githowto.com/ | |
#dont forget about the gui interface... gitk | |
gk | |
----- | |
#start a new repo from existing directory | |
git init . | |
git add . | |
git commit -a -m "initial commit" | |
git remote add origin [email protected]:philosophie/dkind-auto-frame.git | |
git push origin master | |
#get the most recently committed version of a file | |
git checkout foo.html | |
#get a previous version of a file | |
#the following gets lesson.js 2 commits ago | |
git show HEAD~2:html/js/lesson.js > foo | |
#relative to current dir rather than root | |
git show HEAD~2:./lesson.js > foo | |
#checkout to a previous version in the working directory | |
#make sure current version is committed | |
git commit -a -m "checkpoint" | |
#list previous versions | |
git hist | |
#switch to one | |
go xxxx | |
#switch back to current | |
go master | |
#create new local branch | |
git checkout -b <branchName> | |
#delete local branch (merged and unmerged) | |
git branch -d <branchName> | |
git branch -D <branchName> | |
#delete remote branch | |
git push origin --delete <branchName> | |
#show just committed diff | |
git diff HEAD^..HEAD | |
#just the files: | |
git log --name-status HEAD^..HEAD | |
#just the comment | |
git log -1 | |
#list current repo state of files in current directory | |
#equiv to svn list . | |
git ls-tree --name-only HEAD | |
#revert local changes back to previous commit (or any version), deleting all uncommitted changes locally (working dir matches repo) | |
#note the data is still in git somewhere (git hist --all) | |
git reset --hard HEAD | |
#remove directory | |
git rm -r xxx/ | |
#remove changes from the staged commit, but keep the changes in working directory | |
git reset HEAD hello.html | |
#cancel the last commit | |
git revert HEAD | |
#IMPORTANT | |
#undo the last commit, keeping the changes, assuming you did not push the changes publicly yet | |
#if you did push the changes, you can still do it, but will need to force push to get it updated correctly | |
git reset HEAD~1 --soft | |
for instance, say you commit to master instead of a branch, undo | |
it using soft, switch to a branch and commit | |
# undo the last push to master, throwing out the commit | |
# WARNING: once pushed, this erases all trace from the repo and cant be recovered | |
git reset --hard HEAD~1 | |
git push -f | |
#or | |
git push -f origin <sha_of_previous_commit>:master | |
#################################### | |
#working with a team and pull requests | |
#make sure in the master branch | |
go master | |
#do some work... | |
#create a new branch | |
#git co -b ejbranch | |
go -b ejbranch | |
#commit your work | |
#git commit -a -m "comment" | |
gca "comment" | |
git commit -m "BACKOFFICE-XXX #time 8h Work done | |
#upload the work to remote repo | |
#git push origin ejbranch | |
gpush ejbranch | |
#specific to java in eclipse: | |
#before doing a pull request, run maven from commandline to make sure everything compiles correctly | |
mvn clean install | |
#then do a project/clean in eclipse for all to remove maven artifacts that are different from eclipse | |
project/clean | |
#may need to rebase? | |
[8:49:28 AM] Kristian: git fetch -p | |
[8:49:37 AM] Kristian: git rebase origin/master | |
[8:49:42 AM] Kristian: git commit | |
[8:49:47 AM] Kristian: then git push | |
#create a pull request with no reviewers | |
#review all changes in the PR to make sure happy with it | |
#then add reviewers to the PR | |
#wait for the pull request to be merged | |
#while waiting you can work off master branch again | |
go master | |
git pull | |
#delete the local branch | |
#git branch -d ejbranch | |
gb -d ejbranch | |
#repeat the cycle | |
--------- | |
#bring working directory up to date with master | |
#if still in master: | |
git stash | |
go master | |
git stash apply | |
#resolve conflict in a pull request: | |
#first merge master branch changes locally | |
go master | |
git pull | |
go ejbranch | |
git merge master | |
#edit the files that have conflict to get rid of them | |
gca "fixed conflicts" | |
gpush ejbranch | |
------------------------ | |
#IMPORTANT | |
#for when you commit to master before switching to a new branch, but did not push it yet: | |
#undo the last commit, keeping the changes, assuming you did not push the changes publicly yet | |
git reset HEAD~1 --soft | |
#create the new branch, etc | |
############################################### | |
#useful.. follow this with pull to deploy live | |
git commit -a -m "blah"; git push ec2 | |
#remove untracked files | |
git clean -n | |
git clean | |
#add empty dirs to the repo, like log dirs | |
#create a .gitignore inside that directory that contains four lines: | |
#note only do this in the leaf dirs | |
.gitignore: | |
# Ignore everything in this directory | |
* | |
# Except this file | |
!.gitignore | |
then: | |
git add dir | |
#this should also work, but will complain about untracked files presumably | |
find . -type d -empty -exec touch {}/.gitignore \; | |
############################################### | |
#setup git to deploy click project remotely | |
#as ec2-user | |
mkdir /web /web/click | |
mkdir ~/repos ~/repos/click | |
cd /home/ec2-user/repos/click | |
git init --bare | |
cd /web/click | |
git clone /home/ec2-user/repos/click . | |
#now you can do git pulls in the production dir | |
cd /home/repos/click/hooks | |
vi post-receive | |
#( add post-receive hook content, make it executable) | |
#You can add a remote to the code repo with | |
git remote add prod /web/click | |
#With that setup, you can have your post-receive hook do git push prod master. | |
#allow automated push live | |
cd ~/repos/click | |
git config --global push.default simple | |
cd /web/click | |
git config receive.denyCurrentBranch ignore | |
#locally... | |
git remote add ec2 ec2-user@clickredir:/home/ec2-user/repos/click | |
git push ec2 master | |
#commit, push, deploy and reload apache in one line | |
git commit -a -m "blah"; git push ec2; ssh -t [email protected] 'cd /web/click; git pull; sudo /etc/init.d/apache reload' | |
############### | |
#change ips on aws servers | |
git remote set-url web1 [email protected]:/home/ec2-user/repos/click | |
git remote set-url web2 [email protected]:/home/ec2-user/repos/click | |
git remote set-url web3 [email protected]:/home/ec2-user/repos/click | |
############################################### | |
#setup git to deploy cpc project remotely | |
#as ec2-user | |
mkdir /web /web/cpc | |
mkdir ~/repos ~/repos/cpc | |
cd /home/ec2-user/repos/cpc | |
git init --bare | |
cd /web/cpc | |
git clone /home/ec2-user/repos/cpc . | |
#now you can do git pulls in the production dir | |
#push the initial project state | |
#locally... | |
git remote add <remote name, ie web1> ec2-user@<new amazon server>:/home/ec2-user/repos/cpc | |
git push <remote name> master | |
#EDJ - don't do this next as current process is to cd to the production dir and pull via the clone setup | |
#cd /home/ec2-user/repos/cpc/hooks | |
#vi post-receive | |
##( add post-receive hook content, make it executable) | |
##You can add a remote to the code repo with | |
#git remote add prod /web/cpc | |
##With that setup, you can have your post-receive hook do git push prod master. | |
#allow automated push live | |
#not needed if already configured for previous project | |
#cd ~/repos/cpc | |
#git config --global push.default simple | |
#cd /web/cpc | |
#git config receive.denyCurrentBranch ignore | |
#-------------------------------- | |
#add a new web server ec2 instance | |
ami: click_server_3 | |
us-east-1a | |
basic monitoring | |
#locally... | |
git remote add <remote name, ie web1> ec2-user@<new amazon server>:/home/ec2-user/repos/click | |
git push web1; | |
ssh -t ec2-user@<new amazon server> 'cd /web/click; git pull; sudo /etc/init.d/apache reload' | |
#make sure couchbase not running, and that the moxi instance that is running is connect to moxi servers rather than locally | |
#test direct in browser | |
http://ec2-184-73-29-172.compute-1.amazonaws.com/index.html?g=2&debug=prn1! | |
#add to load balancer | |
############################################### | |
#setup git to deploy feed project remotely | |
#as ec2-user | |
mkdir /web /web/feed | |
mkdir ~/repos ~/repos/feed | |
cd /home/ec2-user/repos/feed | |
git init --bare | |
cd /web/feed | |
git clone /home/ec2-user/repos/feed . | |
#now you can do git pulls in the production dir | |
#push the initial project state | |
#locally... | |
git remote add <remote name, ie web1> ec2-user@<new amazon server>:/home/ec2-user/repos/feed | |
git push <remote name> master | |
############################################### | |
#mount one directory to another instead of symlinks so git tracks it | |
#http://stackoverflow.com/questions/86402/how-can-i-get-git-to-follow-symlinks | |
#NOTE these are all done automatically in /etc/fstab, ie: | |
#/root/Dropbox/k8corp/release /web/ccp/html/assets/k8 none bind 0 0 | |
mount --bind /root/Dropbox/k8corp/release /web/ccp/html/assets/k8 | |
mount --bind /root/Dropbox/k8corp/ethan /web/ccp/html/assets/dev/k8 | |
#share modules dir between projects but let git track | |
mount --bind /web/prn/modules /web/cpc/modules | |
mount --bind /web/prn/modules /web/feed/modules | |
mount --bind /web/prn/modules /web/video/modules | |
localhost:/web/cpc# chmod -R +x bin/ | |
localhost:/web/cpc# chmod -R +x cgi-bin/ | |
localhost:/web/cpc# chmod +x cgi-bin/* | |
localhost:/web/cpc# chmod +x bin/* | |
localhost:/web/cpc# chmod +x bin/ZohoReports/UploadTool/jre/bin/* | |
localhost:/web/cpc# chmod +x bin/ZohoReports/UploadTool/bin/* | |
localhost:/web/cpc# ls -lbin/ZohoReports/UploadTool/bin/C^C | |
localhost:/web/cpc# ls -l bin/ZohoReports/UploadTool/bin/C | |
ls: cannot access bin/ZohoReports/UploadTool/bin/C: No such file or directory | |
localhost:/web/cpc# ls -l bin/ZohoReports/UploadTool/bin/ | |
total 32 | |
-rwxr-xr-x. 1 root root 1633 Nov 21 2013 CSVUploadConsole.sh* | |
-rwxr-xr-x. 1 root root 116 Nov 21 2013 CSVUploadGUI.sh* | |
-rwxr-xr-x. 1 root root 478 Nov 21 2013 setEnv.sh* | |
-rwxr-xr-x. 1 root root 1377 Nov 21 2013 UploadFromDB.sh* | |
localhost:/web/cpc# chmod -x bin/ZohoReports/UploadTool/bin/* | |
localhost:/web/cpc# chmod +x cgi-bin/admin/editCpcConfig | |
localhost:/web/cpc# chmod +x bin/unused/aggregateCounts | |
localhost:/web/cpc# cd etc | |
localhost:/web/cpc/etc# cd .. | |
localhost:/web/cpc# cd etc | |
localhost:/web/cpc/etc# chmod +x moxi-cpc | |
moxi-cpc moxi-cpc-local | |
localhost:/web/cpc/etc# chmod +x moxi-cpc* zohocron | |
zohocron zohocronDaily zohocronRT | |
localhost:/web/cpc/etc# chmod +x moxi-cpc* zohocron* | |
localhost:/web/cpc/etc# chmod +-x startupCpc.pl | |
##################################################### | |
#squash commits of a branch | |
#merge the commits of a branch into one to simplify pull requests, etc | |
git rebase -i HEAD~7 | |
#where 7 is the number of commits in the branch | |
#it will show a list of the commits | |
#leave the first line with pick ... | |
#for the other lines | |
#you will replace pick with 's' | |
#and then go ahead and | |
:x | |
#to save and proceed | |
#it should show you how the comments for your squashed commit should look | |
#you can edit it as you like | |
#and then save it | |
:x | |
#now you should be in the command line again | |
#it should show you something like Successfully rebased and updated | |
#now force a push | |
git push -f | |
##################################################### | |
philosophie | |
#github repo comment for approved | |
:shipit | |
---- | |
#for a branch named feature/prompts | |
git branch feature/prompts | |
aka | |
go -b feature/xxx | |
gb feature/xxx | |
#do some work | |
#do some commits | |
gca .... | |
gpush feature/prompts | |
gca ... | |
gpush feature/prompts | |
... | |
#when ready to merge | |
#push branch to github | |
gpush feature/prompts | |
#make a pull request on github | |
#get the shipit squirrel | |
#get the last commit where my branch diverged from master | |
git merge-base feature/prompts origin/master | |
> ea3f7d7159bc31a7855418982ee9f6858355feac | |
#squash commits and edit the commit message | |
git rebase -i ea3f7d7159bc31a7855418982ee9f6858355feac | |
#pushed the squashed version into the branch as a replacement | |
git push -f origin feature/prompts | |
#check github for merge conflicts | |
#go back to master and merge in the branch | |
go master | |
git pull | |
git merge feature/prompts | |
gpush master | |
#delete branch in github | |
#delete local branch | |
git branch -d feature/prompts | |
############## | |
rebase example | |
go -b feature/sponsors | |
gca "make sponsors database driven, with images on s3" | |
gpush feature/sponsors | |
#post a PR | |
#do some work inteneded for a new branch | |
git stash | |
go master | |
go -b feature/signup | |
git stash apply | |
gca "implement form submission for signups" | |
gpush feature/signup | |
#make edits to sponsors PR | |
go feature/sponsors | |
gca "more adjustments for PR" | |
gpush | |
#sponsors PR done | |
go master | |
gb -d feature/sponsors | |
git pull | |
#switch back to new branch and rebase off new state of master | |
go feature/signup | |
git rebase master | |
#force push is required | |
gpush -f | |
############## | |
#switch to someone else's branch to test stuff | |
git fetch | |
go branch | |
################# | |
#get a diff since the branch was created | |
#get the last commit where the branch diverged from master | |
git merge-base feature/prompts origin/master | |
> ea3f7d7159bc31a7855418982ee9f6858355feac | |
git diff ea3f7d7159bc31a7855418982ee9f6858355feac | |
############# | |
#keep folder in git but not contents | |
put this .gitignore into the folder, then git add .gitignore | |
* | |
*/ | |
!.gitignore | |
################# | |
#work with a fork of a repo | |
#grab new version of master from the original repo | |
git remote add upstream [email protected]:uport-project/muport-core-js.git | |
git fetch upstream | |
git rebase upstream/master | |
git push origin master | |
#if there is an error about conflict and doesnt seem to resolve (because nothing changed), do | |
git rebase --skip | |
#which skips over just that conflict | |
################# | |
#pull in new master stuff while in a different branch | |
#make sure your branch is committed | |
gcam "lalla" | |
#update local master | |
gco master | |
git pull | |
#switch back the branch and rebase | |
gco branch | |
git rebase master | |
#this will replay your local branch on top of the new local master | |
#################### | |
# see what files changed in a repo between 2 recent commit points | |
git diff --name-only HEAD~10 HEAD~5 | |
#push an expty commit, ie to force a deploy with CI | |
git commit --allow-empty | |
git push ... | |
#################### | |
# work on new dependent branch (newbranch) while waiting to merge pr on dependent branch (prbranch) | |
git checkout -b newbranch | |
# equiv to following if not on prbranch | |
git checkout -b newbranch prbranch | |
#do work on newbranch | |
# lets say pr needs mods | |
gco prbranch | |
# do edits | |
# commit changes to prbranch | |
gcam "cleanup for pr" | |
git push origin prbranch | |
# incorporate changes to prbranch into newbranch | |
gco newbranch | |
git rebase prbranch | |
# resolve conflicts if present (git add + git rebase --continue) | |
# pr gets approved | |
# squash and merge prbranch in github | |
# important non-obvious way to "rebase" newbranch to result of prbranches merge | |
# on newbranch, squash newbranch commits into one commit | |
git log | |
# search for the commit right before newbranch commit | |
# this should be labelled with the text of the last commit of the squashed PR on github | |
git rebase -i <sha of previous commit> | |
# change first letter of each line to 's' except for the first line! | |
# retrieve sha of the resulting squashed commit for use later, aka 'newsha' | |
# which is the firs commit/sha in the output of git log | |
git log | |
gco master | |
git pull | |
# rename newbranch to a temp name, since we will create a new branch based on it | |
git branch -m <newbranch> tmpbranch | |
# recreate our new branch | |
gco -b <newbranch> | |
# cherry pick the squashed commit from tmpbranch to newbranch | |
git cherry-pick <newsha> | |
# force push newbranch to github otherwise it will reject it | |
git push origin <newbranch> -f | |
# newbranch is now "normal" and has original name | |
# pr gets merged | |
# Rebase new branch onto master | |
git pull --rebase origin master | |
######################## | |
# create a gist from clipboard with short url copied to clipboard afterwards | |
gist --paste --shorten --copy --filename "blah" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment