Workflow

Feature Branch Workflow

# This flow uses a work in progress (WIP) branch. Commits to the WIP branch
# should be done often to provide roll back points.
git checkout origin/dev -b wip/branch
git commit -m "spike 1"
git commit -m "spike 2"

# When the feature is complete create a pull request branch and squash the
# WIP branch into it.
git checkout origin/dev -b feature/branch
git merge --squash wip/branch
git review

Pull Request Review Workflow

git review -d {id}

# Implement feedback, amend, and review
git add .
git commit --amend --no-edit
git review

Verify a Gerrit review

Comment “recheck” on the review or find the job in Alfred and run retrigger.

Configuration

Alias

pl = pull --rebase
last = log -1 HEAD
ll = log -1 HEAD --name-status
unstage = reset HEAD --
amend = commit --amend --no-edit

Use Visual Studio Merge for diffs and merges

[merge]
	tool = vsdiffmerge
[diff]
	tool = vsdiffmerge
[mergetool]
	prompt = true
[difftool "vsdiffmerge"]
	cmd = \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
	keepBackup = false
[mergetool "vsdiffmerge"]
	cmd = \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m
	keepBackup = false
	trustExitCode = true

Clean-up

# Replace remote branch
git push origin :<branch>
git push origin <branch>

# Revert ALL local commits
git reset --hard origin/<branch>
git clean -fd

# Remove remote file and keep local
git rm --cached <filepath>

# Remove remote directory and keep local
git rm --cached -r <directory>

# Merge multiple commits into a single commit
git rebase --interactive HEAD~2

Revert

# Revert ALL local commits
git reset --hard origin/<branch>
git clean -fd

#Revert a single file
git checkout -- <filename>

# Replace a single file from another branch
git checkout <branch> -- <filepath>

# Undo rebase
git reset --hard ORIG_HEAD

Reporting

# Git reporting requires the my-get.ps1 module.
git fetch -p
Get-Branches -NotMerged | where { $_.Username -like "Aaron*" } | Format-Table -AutoSize
Get-Branches -NotMerged | where { $_.Branch -NotLike "origin/release*" -And $_.Branch -NotLike "origin/master" -And $_.Branch -NotLike "origin/dev" } | Format-Table -AutoSize

# Search commit history
git log --oneline | Select-String -Pattern ".*voice.*"

# Show commit changes
git show fd1a7f61

Sub-Modules

## Clone with submodules
git clone --recursive mypath

## Update submodules
git submodule update --init --recursive

Change the upstream branch

git branch --set-upstream-to=origin/dev

Patching

## Create a patch from the last commit
git format-patch -n HEAD^

## Apply patch
git apply my-changes.patch