Another developer has deleted and rebuilt a remote branch called "development" which I already have a checked out copy. He did this delete and rebuild to remove some cruft from it. Which is great.
But when I do a "git pull origin development" it keeps getting merge conflicts. Yet I don't want what I have in my copy. I want what is in origin only.
So how do I delete my local copy of it and pull it back down? Or at least pull without merging my local info into it?
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.
In Git, local and remote branches are separate objects. Deleting a local branch doesn't remove the remote branch.
Grab the most up-to-date changes from the origin remote. This step is the “pull without merge” step you asked for in your question. git pull
is the equivalent of git fetch
followed by git merge
.
$ git fetch origin
Get to a clean branch if necessary.
$ git stash
With a clean branch, switch to the development branch if you are not already there.
$ git checkout development
Finally, force your local development branch to point to the same commit as the one on origin.
$ git reset --hard origin/development
Always think twice before using git reset --hard
, as with rm -rf
. It is a sharp, useful tool, but it can destroy work if you are not careful.
To delete a local branch permanently, do:
git branch -D <branch-name>
Fetch changes from the remote repo but do not merge:
git fetch
Now create and checkout a local copy of the remote branch and track it:
git checkout -b development origin/development
git should tell you "Branch development set up to track remote branch development from origin", and that it's switched locally to the development branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With