Wednesday, February 26, 2014

How to Reset your Branch to Remote Code on Github

Overview
Sometimes Github may be giving you issues and not allowing you to reset your local branch with your remote branch. If you don't have any code that you need saved on your local branch, here's a good way of fixing this situation

Solution
Issue these commands:

    git checkout master
    git branch -D <your_branch_name>
    git fetch
    git checkout <your_branch_name>

Explanation of Commands
1) git checkout master - What this does is checkout your master branch so you are no longer on the branch you want to reset
2) git branch -D <your_branch_name> - This deletes your local branch, even if files are not merged from your local machine to your remote github account. This will not delete anything that you have already pushed to github.
3) git fetch - This downloads all of the branches onto your local machine so that you can easily checkout any of them onto your local machine
4) git checkout <your_branch_name> - This checks out the branch you want to be on that was just downloaded from github.

Conclusion
This will reset all your local changes, so you have to be careful that your local changes are saved. You should be able to issue the command "git stash" before, then "git stash pop" after in order to maintain local changes, but I need to test this first to make sure it works before saying for sure.



NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

No comments :

Post a Comment