= Git Tips = [[PageOutline(2,Tips,inline)]] This page is a collection of useful git tips. == Apply a commit to multiple branches == 1. Checkout master branch {{{ #!sh git checkout master }}} 1. Make commit {{{ #!sh git commit -m "Fixed bug" }}} 1. Checkout stable branch {{{ #!sh git checkout stable }}} 1. Apply the last commit from master to this branch {{{ #!sh git cherry-pick master }}} 1. Repeat steps 3-4 as necessary 1. PROFIT! == Ignore changes in a tracked file == To ignore: {{{ #!sh git update-index --assume-unchanged }}} To stop ignoring: {{{ #!sh git update-index --no-assume-unchanged }}} == Stash untracked files == At times you will be working on a branch with untracked files (new files) and you'll need to checkout master to apply a bug fix. First, add the untracked files to the index: {{{ #!sh git add }}} Now do a regular stash: {{{ #!sh git stash }}} At this point you can checkout whatever branch you want and do what you need to do. When you're done, checkout your original working branch again and pop the changes from your stash: {{{ #!sh git stash pop }}} You can remove the files you indexed from the index if you want, as to not pollute your next commit: {{{ #!sh git rm --cached }}} == Merge a remote branch == First, add the repo: {{{ #!sh git remote add }}} Now fetch in the changes: {{{ #!sh git fetch }}} You'll want to do a diff against your branch to see what will be merged: {{{ #!sh git diff master / }}} If you're happy with the changes, go ahead and merge it: {{{ #!sh git merge / }}} == Delete the last commit == {{{ #!sh git reset --hard HEAD~1 }}} == Delete a remote branch == {{{ #!sh git push : }}} == Merge a topic branch == In this example we assume that your topic branch, , is off master and that you are currently in your topic branch 1. Squash/reword/edit any commits if need be {{{ #!sh git rebase -i master }}} 1. Rebase your topic branch on top of current master {{{ #!sh git rebase master }}} 1. Change to master {{{ #!sh git checkout master }}} 1. ('''Fast-forward''') merge your topic branch into master {{{ #!sh git merge }}} 1. Delete your local topic branch (see above tip for remote deletion) {{{ #!sh git branch -d }}}