Print the total number of commits per day containing a pattern in git


You want to print a summary of commits in git that contain a certain pattern (‘number’) ordered by date and with the total number of commits per day


You can use the following for the patter ‘number’

git log --pretty=format:'%h %ad | %s%d [%an]' --date=short | grep 'number' | awk '{print $2}' | sort -r | uniq -c | awk '{ print $2,$1}'

The last awk command is to swap the date with the total number

The output should be something like the following

2024-06-18 2
2024-06-17 3
2024-06-14 1
2024-06-13 1
2024-06-12 1
2024-06-11 4
2024-06-10 3

Removing git branches from local repository


You would like to remove your local branches that were used to track remote branches that no longer exists (deleted after merge).

git branch -a


To delete your local branch you could use the following:

git branch -D branch_to_delete

And to to delete the remote tracking branching you could use the following:

git branch -rd origin/branch_to_delete

git apply name_of_file.patch does not work


You are given a patch file to apply to your git repository but using git apply does not work. No errors reported but no changes applied neither.


Try to use the patch command command possibly with the -p1 parameter like:

patch -p1 < path_to_the_patch_file.patch

NOTE: Make sure that you are in the right folder relative to the file path in the patch file

SSL received a record that exceeded the maximum permissible length.


You want to install rbenv, but when you are trying to clone the code with:

git clone ~/.rbenv

you get the following error:

fatal: unable to access '': SSL received a record that exceeded the maximum permissible length.


If you are behind a proxy server make sure that you add your proxy server details in your ~/.bash_profile and source the file afterwards.

So first add the details of your proxy like:

export http_proxy=
export https_proxy=

And finally source the file before running the installation again:

source ~/.bash_profile

How to display the git last commit of every file in a list with ruby


You want to display the last commit of every file that you have in a list.


Let’s say that you have the following file list in an array:

file_list = ["Gemfile", "Gemfile.lock", ".ruby-version"]

in order to be able to get the last commits of each of the files in ruby do the following:

file_list.each do |f|
  puts %x[git log -n 1 #{f}]

Session secret should not be included in version control near line …


After using brakeman to test for security issues in your rails application you get the following warning about the config/initializers/secret_token.rb file:

Session secret should not be included in version control near line xx


Since you may have already pushed the original secret_token.rb in your version control you may need to do the following.

  • Make a copy of the file : cp config/initializers/secret_token.rb config/initializers/copy_of_secret_token.rb
  • Delete the original file that is also on your version control: rm config/initializers/secret_token.rb
  • Add it to .gitgnore
  • Commit your changes and push to your version control: git commit -a -m “remove secret token and include it in .gitignore”, git push (origin master)
  • Create a new secret key by running: rake secret
  • Copy the value from above to the file config/initializers/copy_of_secret_token.rb replacing the original value of config.secret_key_base
  • Rename the file to secret_token.rb again: mv config/initializers/copy_of_secret_token.rb config/initializers/secret_token.rb
  • Check that the new file is not listed in git when you do : git status

Refreshing locally remote branches that have been deleted in git


You would like to refresh your local git repository after deleting some remote branches, usually after merging them to a develop,master etc repository, so doing branch -a or branch -r would not display them anymore.


You would need to issue the following git command:

git remote prune origin

And then doing a branch -r or branch -a should not display the deleted remote branches anymore.

fatal: cannot exec ‘/tmp/…/’: Permission denied – Capistrano, Dreamhost, permission denied for


When trying to use the new Capistrano 3.x to set up your rails project in a dreamhost account, you get the following error complaining that the script copied to your account by capistrano cannot be executed as the permission is denied:

fatal: cannot exec '/tmp/': Permission denied


It seems that Dreamhost, and quite possibly other hosting providers are not allowing executables from the /tmp directory, which is where Capistrano places the script. So in order to be able to execute the script you can change the directory where the script is copied in the first place and put it in your home directory. You can do that by adding the following to the config/deploy.rb file:

set :tmp_dir, "/home/dh_user_name/tmp"

Pushing and getting the tags from a remote git repository


You want to tag your branches in a remote repository and share the tags with other users, but usually the git pull and git push do not update the tags.


According to the git documentation:

By default, the git push command doesn’t transfer tags to remote
servers. You will have to explicitly push tags to a shared server
after you have created them. This process is just like sharing remote 
branches — you can run git push origin [tagname].


If you have a lot of tags that you want to push up at once, 
you can also use the --tags option to the git push command. 
This will transfer all of your tags to the remote server that 
are not already there.

But when doing either a git pull origin [repo] or git fetch origin [repo] the tag list does not seem to be updated.

In this case try the following:

git pull origin [repo] --tags

And the list should contain all the tags in the remote repository.

Get github to link your commits to your user account if you have more than one git accounts


You would like to link the commits to a github repository to your github account but you may have different git accounts (ie gitolite etc).
So you would need to specify in the config file which account you want to use.


There is a help page in github that describes this problem here, but they recommend to change your global settings which is maybe not what you want.
So you could the following to change only the current project settings:

cd ~/my_project
git config --local"your_github_account_email"

Or add the following to your .git/config file inside your local repository:

  email =
  name = Firstname Surname

And to check the settings:

git config --local -l
git config --global -l