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 (test-b
), another one has been re-named, or equivalently deleted and re-created with a new name (ie: v_123
is now v123
), 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 (How to clone all remote branches in 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?
In GitHub Desktop, click Current Branch. Click Choose a branch to merge into BRANCH. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. Note: If there are merge conflicts, GitHub Desktop will warn you above the Merge BRANCH into BRANCH button.
Git fetch commands and optionsFetch all of the branches from the repository. This also downloads all of the required commits and files from the other repository. Same as the above command, but only fetch the specified branch. The --dry-run option will perform a demo run of the command.
Not sure, this is what you expect.
git fetch origin
git reset --hard origin/master
git clean -f -d
The above commands 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
.
WARNING: All your untracked files will be gone when you do
git clean -f -d
.
Lemme know, if any questions.
I think you want to:
git fetch --all -Pp
where:
git fetch
Download objects and refs from another (remote) repository
--all
fetch all remotes.
-P
remove any remote-tracking references that no longer exist on the remote.
-p
remove any local tags that no longer exist on the remote.
for more use git fetch --help
We have a similar command that only perform a prune not fetching remote data:
git remote prune origin
We can also set the git client to do the remote prune every time we fetch data:
git config --global fetch.prune true
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