Git Clean-Up Commands

Sometimes you may find a git repository with a lot of branches and not all of them necessary.

Because of that, you may want to do some cleanup, so I’ve prepared a list of very useful commands:

  • Remove Merged Branches

just to see them / or number them

git branch -r --merged origin/master | grep -v "^.*master" | sed s:origin/:: | xargs -n 1 echo

git branch -r --merged origin/master | grep -v "^.*master" | sed s:origin/:: | wc -l

and to really delete those branches

git branch -r --merged origin/master | grep -v "^.*master" | sed s:origin/:: | xargs -n 1 git push origin --delete 

* these commands take care of the `master branch. If you need to keep another branch, just change the grep -v “^.*master”

  • Remove every remote (beside ‘master)

even much simple + you can use similar commands to see/number these branches

git branch -r | grep -v "^.*master" | sed s:origin/:: | xargs -n 1 git push origin --delete 

How to get the diff between all the commits that occurred on a specified timeframe in Git?

Sometimes you find out from QA department that starting with a specific date an endpoint from your application started to work a little bit slowly

if that date is last week, or I don’t know, it happen last month, the simple solution it will be to do an export of all commit between two specific days

git log -p master@{2016-06-02}..master@{2016-06-02}

git log -p master@{2016-06-02}..master@{now}

git log -p master@{1.hour.ago}..master@{now}

for more info see this page
git-log

Install ruby ‘pg’ library problems

After I’ve installed postgresql, the problem with ‘pg’ library persisted


sudo gem install pg -v '0.11.0'
.....
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary

The solution for this is to run the installer in this way:


sudo env ARCHFLAGS="-arch x86_64" gem install pg

How to fix grunt error “Cannot find module ‘lru-cache'”

To fix this error is very simple: you just have tot clean your node modules:

$ grunt install:development
Loading "Gruntfile.js" tasks...ERROR
>> Error: Cannot find module 'lru-cache'
Warning: Task "install:development" not found. Use --force to continue.

Aborted due to warnings.

john@C370012100004 /C/projects/nodejsp(develop)
$ rm -rf node_modules && npm cache clean && npm install