[[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
----

== Using `ssh-agent` to save your SSH key's passphrase

If you have to enter your SSH key's passphrase whenever working with the repository from the command line, you might want to use the ssh-agent to remember the passphrase for you.

Before using the `ssh-agent` you will see a prompt to enter your passphrase after each git command.

[source]
----
[amq-repo]$ git pull --rebase upstream master
Enter passphrase for key '/home/<username>/.ssh/id_rsa':
----

To add your passphrase to the `ssh-agent`:

[source]
----
[amq-repo]$ ssh-add
Enter passphrase for /home/<username>/.ssh/id_rsa:
----

After entering your passphrase you will see confirmation that your passphrase has been saved:

[source]
----
Identity added: /home/<username>/.ssh/id_rsa (/home/<username>/.ssh/id_rsa)
----

== 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>/strimzi-kafka-operator.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>
----
