Gabriel Gabriel - 1 year ago 175
Git Question

Sync all branches with git

I push code from two main locations: my PC at home and my laptop at work. I use Github to store my repos.

This is the scenario: I did some work in my PC on a repository I've been working on for some time (both in my PC and in my laptop), and ended with the following branches:

$ git branch
* master
* v123
* test-b

which I pushed to Github. So far so good.

Now I'm on my laptop and this is what I see before attempting to pull anything:

$ git branch
* master
* v_123

This is an old version of my repo in my laptop (since I've been working in my PC) where the differences are: a branch is missing (
), another one has been re-named, or equivalently deleted and re-created with a new name (ie:
is now
), and lots of things have changed possibly in all branches.

I want to sync all my branches into my laptop and have them correctly tracked. I've looked at two of the most up-voted questions regarding branch cloning/fetching (Clone all remote branches with Git?; How to fetch all git branches) and right now I'm a bit lost.

Is there some easy to use
git sync-branch --all
command that can be used to sync my laptop with the latest state of the repo in Github?

Answer Source

Not sure, this is what you expect.

git fetch origin && git reset --hard origin/master && git clean -f -d

The above command will synchronize the remote repo with the local repo. After the above command execution, your local repo will be like the mirror image of your remote repo.

If you want to retain the changes as unstaged files, use --soft instead of --hard.

IMPORTANT: All your untracked files will be gone when you do git clean -f -d. Please be aware of that.

Lemme know, if any questions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download