Skip to content

Latest commit

 

History

History
105 lines (83 loc) · 2.62 KB

git-tips.adoc

File metadata and controls

105 lines (83 loc) · 2.62 KB

Git tips

Delete branches

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

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

To delete one branch:

$ git checkout master
$ git branch -D <branch-name>

Resolve conflicts

To resolve a merge conflict in an existing pull request:

$ 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.

$ 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.

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

To add your passphrase to the ssh-agent:

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

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.

  1. Check out a new topic branch from upstream/master as you normally do.

    $ git fetch upstream
    $ git checkout -b <new-topic-branch> upstream/master
  2. If you have not yet added that writer’s remote repository, add it now.

    $ git remote add -f <user> [email protected]:<user>/RH-OpenJDK-Docs.git
  3. Rebase to bring in the changes that are in that user’s outstanding origin/<merge-request-branch> branch.

    $ git rebase <user>/<merge-request-branch>

    (you’ll see the following response)

    First, rewinding head to replay your work on top of it...
    Fast-forwarded <new-topic-branch> to <user>/<merge-request-branch>