Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update local list of branches in git

Tags:

git

I m trying to update the local list of my branches. I can see only 3 while remote are 11. I tried this solution with prune command and despite my config file was updated when I press git branch -a I get the same result as before (the remote branches with red letters and in first place 'remotes/origin/HEAD->origin/master'.

like image 253
Dimitrios Markopoulos Avatar asked Oct 31 '25 15:10

Dimitrios Markopoulos


2 Answers

If you don't see the branches after the command you entered, it probably means they don't exist locally. Your computer now knows they exist, but hasn't physically and locally created them yet. Switch to one of the remote branches that are "missing":

git checkout branch_name

... and git should create the branch locally.

Also, remember that git remote update fetches from ALL REMOTES, while what you probably want to do (what is probably sufficient enough) is git fetch origin which fetches only from one remote called origin. It probably doesn't change much in your case, but please make sure you understand the difference.

Further clarification in response to comment

git fetch downloads objects and refs from a remote repository - ONE repository only. So git fetch origin will download all that stuff from the repository called origin.

If you you use git remote update, it will download objects and refs from ALL repositories (in case you more the just origin configured - you probably don't). It is essentially the same as you would execute git fetch --all.

To summarize, you usually want to use git fetch origin - this will update your local state with regards to what exists remotely. Updating doesn't mean it will physically create the branches for you. It's just information that they exist and may be checked out. It is git checkout branch_name which then creates a selected branch physically on your local computer.

like image 84
Maciej Jureczko Avatar answered Nov 02 '25 06:11

Maciej Jureczko


Try to explicitly specify that you want to fetch all the remote branches:

git fetch origin '+refs/heads/*:refs/heads/*'

To make this a permanent setting do:

git config remote.origin.fetch '+refs/heads/*:refs/heads/*'

Local copy of a branch is only created when you actually check it out. So if you have remotes/origin/branchX then to have local branchX you would want to git checkout branchX

like image 40
Zloj Avatar answered Nov 02 '25 06:11

Zloj