Skip to content

Instantly share code, notes, and snippets.

@markjames
Created September 1, 2011 10:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markjames/1185867 to your computer and use it in GitHub Desktop.
Save markjames/1185867 to your computer and use it in GitHub Desktop.
Going git
# The following commands
# need to be run once to set-up git
# Install git (you may have this already, type git then hit [ENTER] in Terminal to check)
cd ~/Downloads && curl -OL "http://git-osx-installer.googlecode.com/files/git-1.7.6-x86_64-snow-leopard.dmg" && open ~/Downloads/git-1.7.6-x86_64-snow-leopard.dmg
# Start a new Terminal window
# I don't have a command for this one
# Install the Git Flow extension
curl -OL http://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh && sudo chmod a+x gitflow-installer.sh && sudo ./gitflow-installer.sh && rm ./gitflow-installer.sh
# Install the Git Subtree extension
curl -OL https://raw.github.com/apenwarr/git-subtree/master/git-subtree.sh && mv git-subtree.sh "$(git --exec-path)"/git-subtree && sudo chown root:admin "$(git --exec-path)"/git-subtree && sudo chmod 755 "$(git --exec-path)"/git-subtree
# Setup your global git name/email
git config --global user.name "Firstname Lastname"
git config --global user.email "email@example.com"
# Turn on git colours
git config --global color.ui true
# Setup SSH key
ssh-keygen -t rsa -f "id_rsa_made"
mv id_rsa_made ~/.ssh/id_rsa_made && mv id_rsa_made.pub ~/.ssh/id_rsa_made.pub
sudo ssh-add ~/.ssh/id_rsa_made
# Copy your public key into your clipboard (ready to paste into Beanstalk)
cat ~/.ssh/id_rsa_made.pub | pbcopy
# Now go to Beanstalk and give them your key
# Optionally restyle your Terminal prompt to include the current branch
mate ~/.bash_profile
# …then copy the following into the bottom of your .bash_profile
function parse_git_branch_name {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
function parse_git_branch_color {
local CURRENT_GIT_BRANCH=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\\1/'`
if [[ $CURRENT_GIT_BRANCH =~ .*master.* ]]
then
# Red for master
echo -e '38;5;196m'
elif [[ $CURRENT_GIT_BRANCH =~ .*develop.* ]]
then
# Green for develop
echo -e '0;32m'
elif [[ $CURRENT_GIT_BRANCH =~ .*feature/.* ]]
then
# Blue for features
echo -e '38;5;45m'
elif [[ $CURRENT_GIT_BRANCH =~ .*hotfix/.* ]]
then
# Orange for hotfixes
echo -e '38;5;202m'
elif [[ $CURRENT_GIT_BRANCH =~ .*release/.* ]]
then
# Bright Yellow for releases
echo -e '38;5;226m'
else
# Lemon for everything else
echo -e '38;5;230m'
fi
}
PS1="\[\033[0;37m\]\h:\u\[\033[0m\] \W\[\033[\$(parse_git_branch_color)\]\$(parse_git_branch_name) \[\033[0m\]\$ "
# The following commands
# are all per project
#
# Get into the right directory
cd ~/whereyoukeepyourvhosts
# Clone the Beanstalk Repo
git clone --origin=beanstalk --recursive git@[company].beanstalkapp.com:/[project].git [vhost/folder/you/want/to/create]
# origin=beanstalk makes the reference to the main remote repository be called 'beanstalk' rather than 'origin'
# Did it fail? Lets debug
# ssh -vT git@[company].beanstalkapp.com
# Setup Git Flow
git flow init
# Then hit enter UNTIL you get to the line that says Version tag prefix []:, then press v then hit Enter
# Get started!
git flow feature start html-templates
mate .
# Do some work (you have to fill this bit in)
# Check what changes you've made
git status
# Add or remove files
git add path/to/my/file/i/added/or/changed
git rm path/to/the/file/i/deleted
# Commit your changes
git commit
git commit -m "Did some work"
git commit -a # If you are lazy and want it to add/rm ALL files that have changed for you
# Oops! Undo that commit
git reset
# Finish your feature
git flow feature finish html-templates
# Update your develop branch
git pull beanstalk develop
# Resolve any conflicts
# Push your changes back to Beanstalk (__make sure you're on the develop branch__)
git push beanstalk develop
# Add the CMS as a subtree
# git subtree add --squash --prefix=web --message="Added subtree for CMS" git@[company].beanstalkapp.com:/[cms-project].git master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment