-
List branches that are already merged. (Found this here: Stackoverflow post)
git branch --merged master #lists branches merged into master git branch --merged lists #branches merged into HEAD (i.e. tip of current branch) git branch --no-merged #lists branches that have not been merged
-
Merge trunk into branch
git commit -am "Current Changes" git fetch git pull origin master
-
See all branches including remote branches
git branch -a
-
Checkout previous branch. Found this gem in this stackoverflow post
git checkout -
-
Remove all local untracked files
git clean -f -d
-
Revert a file to remote version
git reset --hard origin/<branch>
-
Removes all files that are tracked but are also part of the ignore file.
git rm -r --cached . git add . git commit -am "Removing unwanted files"
-
Change the last commit message
git commit --amend
-
Undo the last commit
git reset --hard HEAD~1
-
Remove a file from a git add that hasn't been committed yet
git reset <filename>
-
Git Pull vs Git Fetch: Pull does a fetch then merge where a Fetch pulls changes but keepsing them in refs/remotes//
-
Rename a local branch
git branch -m <oldname> <newname> git branch -m <newname> #If you want to rename the current branch
-
Get edited line information. Found this GEM in a response to this stackoverflow question.
git log --author="<author_name>" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' > output_file.txt
-
Get commit stats
git shortlog -s -n -e