git pull -f (git force pull)

3 Dec 2012

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 
comments powered by Disqus

  « Previous: Next: »