Created
December 10, 2015 13:30
-
-
Save erdbehrmund/84aafe2cb50046eb8a25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ===Useful Scripts and configuration=== | |
| In order to use the following scripts, create a file named as indicated with the given contents, make it executable with chmod +x, and place it in the same location as the git executable (or anywhere in your path). Once the file is in place, it can be used as any other normal git command. For example: | |
| git integrate | |
| git ship | |
| git mdiff repo/branch | |
| ====git-integrate==== | |
| The git-integrate script pulls in the latest changes from the master origin repository into your local master branch and rebases your current branch on top of those new changes thereby integrating the new changes into your branch without needing another merge commit. | |
| Note that rebasing should only be done on branches that haven't been made public or are being squashed and prepared to be fast-forward merged into master prior to deletion. In other words, when the branch is still local and under development, this script should be run liberally with the command 'git integrate' to keep up with the latest changes. However, once the branch has been published for review, this script shouldn't be run again until the changes are ready to be finalized and fast-forward merged to master. | |
| This script must be run from the branch you are intending to integrate the changes from master into. | |
| #!/bin/sh | |
| BRANCH=$(git branch | grep '\*' | cut -c3-) | |
| if [ "$BRANCH" = "master" ]; then | |
| echo "already on master branch" | |
| exit 1 | |
| fi | |
| set -x | |
| git checkout master | |
| git pull origin master | |
| git checkout "$BRANCH" | |
| git rebase "$@" master | |
| Example Usage: | |
| git checkout -b branch_name | |
| vi hello.c | |
| git commit -a | |
| vi Makefile | |
| git commit -a | |
| (Meanwhile some changes have happened to the remote repository) | |
| git integrate | |
| vi more_changes.c | |
| git commit -a | |
| (Meanwhile some more changes have happened to the remote repository) | |
| git integrate -i | |
| ====git-ship==== | |
| The git-ship script checks out the master branch and performs a fast-forward only merge to pull the changes from the branch into the master branch, pushes those changes to the origin repository, and then deletes the branch. | |
| This script should be directly after the git-integrate script above as it will only perform a fast-forward merge which means the branch must have first been rebased to the current tip of of the master branch. | |
| This script must be run from the branch you intend to fast-forward merge to master. | |
| #!/bin/sh | |
| BRANCH=$(git branch | grep '\*' | cut -c3-) | |
| if [ "$BRANCH" == "master" ]; then | |
| echo "already on master branch" | |
| exit 1 | |
| fi | |
| set -x | |
| git checkout master | |
| git merge --ff-only "$BRANCH" | |
| if [ $? -ne 0 ]; then | |
| git checkout "$BRANCH" | |
| exit 1 | |
| fi | |
| git push origin master | |
| git branch -d "$BRANCH" | |
| Example Usage: | |
| git checkout -b userid_rt####_short_desc | |
| vi hello.c | |
| git commit -a | |
| (Meanwhile some changes have happened to the remote repository) | |
| git integrate | |
| vi more_changes.c | |
| git commit -a | |
| (Meanwhile some more changes have happened to the remote repository) | |
| git integrate | |
| (All changes are correct and ready to "ship" to the "centralized" repository) | |
| git ship | |
| ====git-mdiff==== | |
| The git-mdiff script is used aid with reviewing all of the differences introduced by all of the commits on a branch. It works by figuring out the merge base and showing all diffs between that commit and the tip of the branch in question. | |
| #!/bin/sh | |
| BRANCH="$1" | |
| [ -z "$BRANCH" ] && BRANCH=HEAD | |
| git diff $(git merge-base master "$BRANCH") "$BRANCH" | |
| Example Usage: | |
| git fetch | |
| git mdiff origin/branch_name | |
| ====Configuration==== | |
| '''Editing configuration file''' | |
| git config -e --global | |
| '''Useful aliases''' | |
| lol = log --graph --decorate --oneline --all | |
| ci = commit | |
| co = checkout | |
| st = status | |
| afetch = fetch --all --prune | |
| br = branch | |
| ===Miscelaneous tricks=== | |
| '''Moving master into new branch after 2 local commits''' | |
| git branch my_spiffy_branch | |
| git reset --hard HEAD~2 | |
| This reverts 2 latest commits irrevocably! | |
| Make sure you save a diff if you need it later. | |
| git push origin my_spiffy_branch | |
| '''Moving master into new branch before commit''' | |
| git checkout -b my_spiffy_branch | |
| git commit -a -m "shiny new code" | |
| '''Cleaning up a tree (delete all files that are not in the tree)''' | |
| git clean -xdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment