Posted in Code Snippets, GIT

Git pull : Ignoring local changes

When you are in a situation to initiate git to a directory which is already developed and you need to pull changes from the remote ignoring local changes, you will not be allowed to use:

git pull origin master

In such case, after initializing git using git init you need to hard reset the head.

Step 0: Git Initialization

git init
git remote add origin https://github.com/<repo>

Step 1: Fetch all the changes from the remote

git fetch --all

Step 2: Reset the master branch now

git reset --hard origin/master

Step 3: Pull from master

git pull origin master

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s