0

I have a setup where I am working on a desktops in two different locations. For each, origin is set as a GitHub repo. When I'm working on computer A and I finish and merge a branch I do:

git branch -d <somebranch>
git push -d origin <somebranch>
git checkout master
git push

Then say I switch to my other system to work from there, I do:

git fetch
git pull

and I delete the local copy of that same branch that I managed to finish up on the other system (which I'd been working on previously on this one)

git branch -d <somebranch>

However, I still see when doing

git branch -a

that the

remotes/origin/<somebranch>

still exists.

I then delete it again like I did from the other computer:

git push -d origin <somebranch>

But is this always the way it has to be done? I'm wondering if there is a method with fewer steps that allows things to 'sync' a bit more intuitively. I'm basically not sure if all these manual deletions are the norm, and would be interested to hear if I'm missing some important details about common Git commands. Thanks

teepee
  • 2,620
  • 2
  • 22
  • 47
  • 1
    `git fetch --prune` will remove the old remote tracking branches. – Jeff Puckett May 25 '18 at 16:49
  • also, there's no need to run `git fetch && git pull` because `pull` will run `fetch` first. it's synonymous to `git fetch && git merge` – Jeff Puckett May 25 '18 at 16:52
  • Ah prune! Nice thanks. I forgot about the fetch vs pull thing. Thanks for reminding me. I guess I'm wondering the best way to "sync" each to the GitHub repo each time I finish using one system or start using another. Before leaving one location I make sure all branches and master are committed then I do `git push` in each branch (is there a way to do this all at once?) And then at the other computer would checkout each branch and do `git pull` in each, and then I guess run a prune all too now. Is there a simpler way? – teepee May 25 '18 at 16:57
  • well you can push multiple branches in one command `git push origin develop master foobranch` and you can search I'm pretty sure I've seen other questions on here where people are trying to keep their local branches in sync with the remote with the use of some scripting. – Jeff Puckett May 25 '18 at 17:11
  • Possible duplicate of [fetch from origin with deleted remote branches?](https://stackoverflow.com/questions/5751582/fetch-from-origin-with-deleted-remote-branches) – Robin Green May 25 '18 at 20:54

0 Answers0