git pull -f (git force pull)

Git has a “force push” option (git push -f remote branch), but it doesn’t have a “force pull” option (like git pull -f remote branch).

This works:

% git fetch remote branch
% git reset --hard FETCH_HEAD
% git clean -df

Or, as a function for your bash/zsh config file:

gpuf () {
   # git pull -f $1
   remote=${1:?"need remote to force pull from"}

   current_branch=$(git symbolic-ref -q HEAD)
   if [ $current_branch = 'HEAD' ] ; then
       echo "On a detached head. Exiting..."
       exit 1

   git fetch $remote $current_branch
   git reset --hard FETCH_HEAD
   git clean -df 

Share This


One Response to git pull -f (git force pull)

  1. […] 2012 Tagged:  Blog: Desenvolvimento Interessante esta dica que eu achei neste blog aqui. O git, de acordo com a dica, possui uma função de forçar o push ( git push -f remote branch ), […]

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>