Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is what I use everyday at work whenever GitX-L is not cutting it.
# clone branch
git checkout -b <branchName> origin/<branchName>
# make sure ssh is working
git ls-remote
# back to master
git reset --hard HEAD
# revert many commits
git reset --hard commit_id
# delete local branch
git branch -D bugfix
# delete remote branch
git push origin :<branchName>
# delete remote branches that have been been removed by OTHERS
git remote prune origin
# rename local branch
git branch -m old_branch new_branch
# rebase fast-forward so your commit goes on top
# get nice linear commit log instead of commit logs
# RUN FULL TEST SUITE
git checkout my_branch
resync #I made this an alias, see below
git checkout master
git merge my_branch --squash # squash (multiple commits) and prep for a new commit
git commit -m "Story title [storyid]"
git push
# resync current branch with master
git fetch
git checkout master
git pull
git checkout my_branch
git rebase master # rewrite history so it looks like the team is well coordinated
# resyncs current branch
function resync() {
if [[ -z "$1" ]]; then BASE='master'; else BASE=$1; fi
# BRANCH=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/ \(.*\)/\1/'` # not a good implementation
BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` # this one is much better
if test "$BRANCH" = "master"; then
git fetch; git pull --rebase
printf "BRANCH '$BRANCH' has been resynced with upstream.\n"
return;
fi
git checkout $BASE; git fetch; git pull;
git checkout $BRANCH; git rebase $BASE;
printf "BRANCH '$BRANCH' has been resynced with '$BASE'.\n"
}
#soft reset so you can do one big commit (just got to get the count right)
git reset --soft HEAD~COUNT
# continue resolving merges
git rebase --continue
# show stash
git stash list
# look at all of your git activity
git reflog
# amend staged changes to last commit
git commit --amend
# pull a SPECIFIC branch & put your changes after it
git pull --rebase origin release-VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment