Search code examples
gitversion-control

Update everything in remote git repository from origin


I have created a simple git repository that contain just programe.txt file. After that I created a remote repository in remote folder, so the project is now looks like this:

D:.
├───local
│       programe.txt
│
└───remote
    └───local
            programe.txt

Then I created user2 branch from remote repository and I added programe2.txt file to this branch. To push all changes, I entered these commands:

git pull origin master
git push origin user2

I merged user2 into master from origin repo. Everything just worked fine until I deleted user2 branch when I was in origin repo; because in remote repo I have user2 branch, but it does not exist in origin repo:

D:\Git\local>git branch -a
* master
D:\Git\remote\local>git branch -a
* master
  user2
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

How can I update everything (like branch state) from origin repo?

I have tried these command but none of them worked:

git pull origin
git pull --rebase
git remote update origin [--prune]
git fetch [--all]
git push origin --delete user2
git reset [--hard]

Solution

  • because in remote repo I have user2 branch, but it does not exist in origin repo:

    Then a simple git fetch would restore the remote tracking branch origin/user2 that you deleted. See How do I delete a Git branch locally and remotely?.

    How can I update branches state from origin when I am in cloned repo?

    If your goal is to also delete the user2 branch on the origin repository, you would need to push its deletion: git push --delete origin user2