Difference between revisions of "Git & Atlassian"

From Briki
Jump to: navigation, search
(Handy aliases)
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
=== Getting started ===
 +
<pre>
 +
git config --global user.name "John Doe"
 +
git config --global user.email [email protected]
 +
git config --global log.mailmap true
 +
 +
git config http.proxy http://myproxy:8080
 +
</pre>
 +
 +
=== Handy aliases ===
 +
<pre>
 +
git config --global alias.lo "!git log --pretty=format:'%C(red)%h%Creset %C(yellow)[%p]%Creset %<|(140)%s %C(green)(%ci)%Creset %C(bold blue)<%aN>%Creset'"
 +
git config --global alias.lr "!git log --left-right --cherry-mark --pretty=format:'%m %C(red)%h%Creset %C(yellow)[%p]%Creset %<|(140)%s %C(green)(%ci)%Creset %C(bold blue)<%aN>%Creset'"
 +
git config --global alias.sw "!git show --no-patch --pretty=format:'Commit: %C(red)%h%Creset %C(yellow)[%p]%Creset%C(cyan)%d%Creset%nAuthor:    %C(blue bold)%aN <%aE>%Creset %C(green)(%ai)%Creset%nCommitter: %C(blue bold)%cN <%cE>%Creset %C(green)(%ci)%Creset%n%+B%C(yellow)%+N%Creset'"
 +
git config --global alias.sws "!git show --stat=160 --pretty=format:'Commit: %C(red)%h%Creset %C(yellow)[%p]%Creset%C(cyan)%d%Creset%nAuthor:    %C(blue bold)%aN <%aE>%Creset %C(green)(%ai)%Creset%nCommitter: %C(blue bold)%cN <%cE>%Creset %C(green)(%ci)%Creset%n%+B%C(yellow)%+N%Creset'"
 +
git config --global alias.rlo "!git reflog --pretty=format:'%C(red)%h%Creset %C(yellow)[%p]%Creset %C(cyan)(%gd)%Creset %<|(140)%gs %C(green)(%ci)%Creset %C(bold blue)<%aN>%Creset'"
 +
</pre>
 +
 
=== Simple workflow ===
 
=== Simple workflow ===
 
* Create JIRA issue
 
* Create JIRA issue
* Click "Create Branch" on JIRA issue (check source branch)
+
* Click '''Create Branch''' on JIRA issue
** This will transition the JIRA issue to In Progress
+
** Check source branch is <code>dev</code>
 +
** This will transition the JIRA issue to '''In Progress'''
 
* <code>git fetch</code>
 
* <code>git fetch</code>
* <code>git checkout branchname</code> (this will automatically create the new branch locally, based on the new remote branch)
+
* <code>git checkout feature/JIRA-ID</code>
 +
** This will automatically create the new branch locally, based on the new remote branch
 
* Make changes
 
* Make changes
 
* <code>git commit -am "My commit description"</code>
 
* <code>git commit -am "My commit description"</code>
 
* <code>git push</code>
 
* <code>git push</code>
* Create pull request
+
* Create pull request from <code>feature/JIRA-ID</code> to <code>dev</code>
** This will transition the JIRA issue to In Review
+
** This will transition the JIRA issue to '''In Review'''
* Merge on build success, and optionally delete branch
+
* Merge in stash on build success
** This will transition the JIRA issue to Done
+
** This will transition the JIRA issue to '''Done'''
 +
** Select '''Delete branch''' if the JIRA is complete
 +
* If the remote branch was deleted, <code>git fetch -p</code> will delete the references to those remote branches locally
 
* Delete branch locally if desired, with <code>git branch -d branchname</code>
 
* Delete branch locally if desired, with <code>git branch -d branchname</code>
 +
* Bring the local dev branch up to date with latest changes
 +
** <code>git checkout dev</code>
 +
** <code>git pull</code>
 +
* Set the issue back to '''In Progress''' if more work on the JIRA is required
 +
 +
=== Hook to add branch/issue name to feature branches ===
 +
This enables JIRA/Bamboo integration so that JIRA can detect build status in the Development pane. Add to .git/hooks/prepare-commit-msg (also works on Windows, at least with msysgit).
 +
 +
==== Terse - only include issue ====
 +
<pre>
 +
#!/bin/sh
 +
#
 +
# Automatically adds issue ID to every commit message.
 +
# Modified from the stackoverflow answer here: http://stackoverflow.com/a/11524807/151445
 +
#
 +
 +
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
 +
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
 +
 +
# Get branch name and description
 +
NAME=$(git branch | grep '*' | sed 's/* //')
 +
 +
case "$NAME" in
 +
  feature/*)
 +
# Append issue ID to COMMIT_MSG
 +
# For info on parameters to githooks, run: man githooks
 +
ISSUE=$(echo $NAME | sed 's/feature\/\([A-Z]*-[0-9]*\).*/\1/')
 +
if [ "$ISSUE" != "$NAME" ]; then
 +
  echo -e "\n[$ISSUE]" >> "$1"
 +
fi
 +
esac
 +
</pre>
 +
 +
==== Verbose - include branch and issue ====
 +
<pre>
 +
#!/bin/sh
 +
#
 +
# Automatically adds branch name and branch description to every commit message.
 +
# Modified from the stackoverflow answer here: http://stackoverflow.com/a/11524807/151445
 +
#
 +
 +
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
 +
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
 +
 +
# Get branch name and description
 +
NAME=$(git branch | grep '*' | sed 's/* //')
 +
DESCRIPTION=$(git config branch."$NAME".description)
 +
 +
case "$NAME" in
 +
  feature/*)
 +
# Append branch name and optional description to COMMIT_MSG
 +
# For info on parameters to githooks, run: man githooks
 +
ISSUE=$(echo $NAME | sed 's/feature\/\([A-Z]*-[0-9]*\).*/\1/')
 +
if [ "$ISSUE" != "$NAME" ]; then
 +
  echo -e "\nIssue: $ISSUE" >> "$1"
 +
  BRANCH_PREFIX=""
 +
else
 +
  BRANCH_PREFIX="\n"
 +
fi
 +
echo -e "${BRANCH_PREFIX}Branch: $NAME $DESCRIPTION" >> "$1"
 +
esac
 +
</pre>
 +
 +
=== Standardise committer name/email address ===
 +
Use a .mailmap file in the repository root; this is also recognised automatically by Stash.

Latest revision as of 10:16, 29 March 2016

Getting started

git config --global user.name "John Doe"
git config --global user.email [email protected]
git config --global log.mailmap true

git config http.proxy http://myproxy:8080

Handy aliases

git config --global alias.lo "!git log --pretty=format:'%C(red)%h%Creset %C(yellow)[%p]%Creset %<|(140)%s %C(green)(%ci)%Creset %C(bold blue)<%aN>%Creset'"
git config --global alias.lr "!git log --left-right --cherry-mark --pretty=format:'%m %C(red)%h%Creset %C(yellow)[%p]%Creset %<|(140)%s %C(green)(%ci)%Creset %C(bold blue)<%aN>%Creset'"
git config --global alias.sw "!git show --no-patch --pretty=format:'Commit: %C(red)%h%Creset %C(yellow)[%p]%Creset%C(cyan)%d%Creset%nAuthor:    %C(blue bold)%aN <%aE>%Creset %C(green)(%ai)%Creset%nCommitter: %C(blue bold)%cN <%cE>%Creset %C(green)(%ci)%Creset%n%+B%C(yellow)%+N%Creset'"
git config --global alias.sws "!git show --stat=160 --pretty=format:'Commit: %C(red)%h%Creset %C(yellow)[%p]%Creset%C(cyan)%d%Creset%nAuthor:    %C(blue bold)%aN <%aE>%Creset %C(green)(%ai)%Creset%nCommitter: %C(blue bold)%cN <%cE>%Creset %C(green)(%ci)%Creset%n%+B%C(yellow)%+N%Creset'"
git config --global alias.rlo "!git reflog --pretty=format:'%C(red)%h%Creset %C(yellow)[%p]%Creset %C(cyan)(%gd)%Creset %<|(140)%gs %C(green)(%ci)%Creset %C(bold blue)<%aN>%Creset'"

Simple workflow

  • Create JIRA issue
  • Click Create Branch on JIRA issue
    • Check source branch is dev
    • This will transition the JIRA issue to In Progress
  • git fetch
  • git checkout feature/JIRA-ID
    • This will automatically create the new branch locally, based on the new remote branch
  • Make changes
  • git commit -am "My commit description"
  • git push
  • Create pull request from feature/JIRA-ID to dev
    • This will transition the JIRA issue to In Review
  • Merge in stash on build success
    • This will transition the JIRA issue to Done
    • Select Delete branch if the JIRA is complete
  • If the remote branch was deleted, git fetch -p will delete the references to those remote branches locally
  • Delete branch locally if desired, with git branch -d branchname
  • Bring the local dev branch up to date with latest changes
    • git checkout dev
    • git pull
  • Set the issue back to In Progress if more work on the JIRA is required

Hook to add branch/issue name to feature branches

This enables JIRA/Bamboo integration so that JIRA can detect build status in the Development pane. Add to .git/hooks/prepare-commit-msg (also works on Windows, at least with msysgit).

Terse - only include issue

#!/bin/sh
#
# Automatically adds issue ID to every commit message.
# Modified from the stackoverflow answer here: http://stackoverflow.com/a/11524807/151445
#
 
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
 
# Get branch name and description
NAME=$(git branch | grep '*' | sed 's/* //')
 
case "$NAME" in
  feature/*)
	# Append issue ID to COMMIT_MSG
	# For info on parameters to githooks, run: man githooks
	ISSUE=$(echo $NAME | sed 's/feature\/\([A-Z]*-[0-9]*\).*/\1/')
	if [ "$ISSUE" != "$NAME" ]; then
	  echo -e "\n[$ISSUE]" >> "$1"
	fi
esac

Verbose - include branch and issue

#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
# Modified from the stackoverflow answer here: http://stackoverflow.com/a/11524807/151445
#
 
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
 
# Get branch name and description
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
 
case "$NAME" in
  feature/*)
	# Append branch name and optional description to COMMIT_MSG
	# For info on parameters to githooks, run: man githooks
	ISSUE=$(echo $NAME | sed 's/feature\/\([A-Z]*-[0-9]*\).*/\1/')
	if [ "$ISSUE" != "$NAME" ]; then
	  echo -e "\nIssue: $ISSUE" >> "$1"
	  BRANCH_PREFIX=""
	else
	  BRANCH_PREFIX="\n"
	fi
	echo -e "${BRANCH_PREFIX}Branch: $NAME $DESCRIPTION" >> "$1"
esac

Standardise committer name/email address

Use a .mailmap file in the repository root; this is also recognised automatically by Stash.