1

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]
  • `in remote repo I have user2 branch, but it does not exist in remote repo` something not clear here. Can you do `git fetch` in both directory ? – Ôrel Dec 09 '22 at 21:16
  • Have you taken a look to https://stackoverflow.com/questions/7726949/remove-tracking-branches-no-longer-on-remote – Ôrel Dec 09 '22 at 21:18
  • I mean I have `user2` branch which exist in cloned repo, but it is deleted from origin. How can I update branches state from origin when I am in cloned repo? @Ôrel – Ali A.M.Hassani Dec 10 '22 at 03:42
  • Each repository is *independent*. It exists on its own, and has *its own* branches. Humans use branch names and assign significance to them, but Git doesn't really care. You don't have to use the same names in two different repositories. We *do* use the same names, though, because we are humans and not computers. But just because you delete a name in *one* repository does not mean it is gone from others. They're *independent*. If you want to delete the name from all the clones, you must issue one delete request per clone. – torek Dec 10 '22 at 11:11

1 Answers1

1

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250