[[git-tips]]
= Git Tips

== Delete Branches

To delete all of your branches except the branch you are on:

[source]
----
$ git checkout master
$ for br in `git branch` ; do git branch -D $br ; done
----

To delete one branch:

[source,options="nowrap",subs="+quotes"]
----
$ git checkout master
$ git branch -D _BRANCH_NAME_
----

== Resolve Conflicts

To resolve a merge conflict in an existing pull request:

[source,options="nowrap",subs="+quotes"]
----
$ git checkout _BRANCH_NAME_
$ git branch -u origin _BRANCH_NAME_
$ git pull --rebase upstream master
$ git push -f origin HEAD
----

== Reset Your Fork

If your fork is both ahead of and behind the origin you can reset your fork to match the origin and start with a clean slate.

[source]
----
$ git checkout master
$ git reset --hard upstream/master
$ git push origin master --force
$ git pull upstream master
$ git push origin master --force
----

== Access Another Writer’s Unmerged Commits

This is the process you can use if you need commits another writer has submitted in a merge request that is not yet merged.

. Check out a new topic branch from upstream/master as you normally do.
+
[source,options="nowrap",subs="+quotes"]
----
$ git fetch upstream
$ git checkout -b __NEW_TOPIC_BRANCH__ upstream/master
----
. If you have not yet added that writer’s remote repository, add it now.
+
[source,options="nowrap",subs="+quotes"]
----
$ git remote add -f _USER_ git@github.com:_USER_/enmasse.git
----
. Rebase to bring in the changes that are in that user’s outstanding
 `origin/__MERGE_REQUEST_BRANCH__` branch.
+
[source,options="nowrap",subs="+quotes"]
----
$ git rebase _USER_/_MERGE_REQUEST_BRANCH_
----
+
(you'll see the following response)
+
[source,options="nowrap",subs="+quotes"]
----
First, rewinding head to replay your work on top of it...
Fast-forwarded _NEW_TOPIC_BRANCH_ to _USER_/_MERGE_REQUEST_BRANCH_
----
