Category Archives: Git

Create patches with git format-patch

Git has a wonderful tool that allows you to create patches of the commits in the tree of your project: git format-patch.


 $ git format-patch [<options>] [<since> | <revision-range>]

More information can be seen via man page:

$ git format-patch -h


$ man git format-patch

For example:

$ git format-patch -N

This command generates one .patch file for each of the N commits on the top of your tree. Example:

$ git format-patch -1

Generates a .patch file for the commit on the top of your tree. Increase the number to get one file per commit (for the top 3 commits, use ‘-3’).

To apply the patch, use

$ git am [your-patch].patch



[git] Get commit from github as a patch file

shares in his GitHub Tip: download commits as patches how to save a commit from github into a .patch file:

“By appending .patch to the commit URL, a commit can easily be downloaded as patch.”

Example using commit # 005cdb



Multiple refs on .git/config

Recently I was trying to push my latest patch to Gerrit when I suddenly started to see an error (“suddenly” as I did not relate any recent changes made that could cause the error. More on it next…)

[09:51:10] sdk@f25:~/tools-devel$ git push review
error: dst ref refs/for/master receives from more than one src.
error: failed to push some refs to 'ssh://'
error: dst ref refs/for/master receives from more than one src.
error: failed to push some refs to 'ssh://'

This error is caused by multiple refs tree within refs/remotes/origin. So go to your project’s .git/config file and search for a [remote "origin"] section there and do what you need to do to get just one ref only.

Make sure you read some more on git remote in previous posts:

Git remove remote branch from repo via CLI
Selecting remote repository on git



Git remove remote branch from repo via CLI

Quick shot: To remove a remote branch on your git repo:

git push [remote-name] --delete [branch-name]


dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git branch -r

dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git push origin --delete teste [8:46:33]
remote: Updating references: 100% (1/1)
To ssh://dkreling@:/RobotFramework.git
 - [deleted] test


Selecting remote repository on git

I recently started to work with two remote repositories on git, and then faced a probably common scenario: check the state of each repository (say ‘origin‘ and ‘vertiv‘).

A 20 minute search provided me the best solution:

$ git branch -u [remote-repo]/[branch]

For example:


In this case, origin/master is ahead of vertiv/master by 2 commits, and my local is sync’ed with vertiv/master.

The docs read:

-u <upstream>, –set-upstream-to=<upstream>
Set up <branchname>’s tracking information so <upstream> is considered <branchname>’s upstream branch. If no <branchname> is
specified, then it defaults to the current branch.



Git: two awesome quick commands: –contains and –no-merged

Find branches the commit is on

git branch --contains <commit #>

Sample output:

Screen Shot 2017-10-17 at 10.18.41 PM10-17-17

fetch_weather, implement_axios and master all have the commit # 3dea5b6


Show all branches with unmerged commits to <branch>

git branch -a --no-merged <branch>

Sample output:

Screen Shot 2017-10-17 at 10.22.39 PM10-17-17

remotes/origin/error_handler has not yet been merged into master


Happy git work!