Home > Software engineering >  How can I update my local repository according to the remotly repository?
How can I update my local repository according to the remotly repository?

Time:09-09

I did some changes and I dirty the local repository.
How can I update my local repo to be exactly like the remotly repo (and also update all the submodules)?

I thought to do git pull --rebase but I not sure if it's will give me what that I want.

CodePudding user response:

use git fetch to sync with the remote

then delete untracked files:

git clean -xfd
git submodule foreach --recursive git clean -xfd

then reset changes:

git reset --hard origin/main #update the name branch if needed
git submodule foreach --recursive git reset --hard

Reinit submodules:

git submodule update --init --recursive

Full set:

git fetch
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive

CodePudding user response:

If you mean that you want to discard your changes locally, you can do git restore . If you want to 'save' those changes, then you need to stage and commit first with the following commands: git add . git commit -m "message-you-want-to-send-with-no-spaces-and-in-quotes" Then finally push your code to the branch where you are at with: git push origin branch-where-you-made-these-changes

After that you can double check if is all in order with git status.

Again, only do this if you want your changes to be taken, otherwise use git restore .

  • Related