sensorario
sensorario

Reputation: 21620

update local branches after git fetch

After a command like $ git fetch origin -a

I can read a log like this:

remote: Counting objects: 43, done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 43 (delta 21), reused 0 (delta 0)
Unpacking objects: 100% (43/43), done.
From https://bitbucket.org/...
   e51234feb..212348ca85  feature/PROJCT-1234 -> origin/feature/PROJCT-1234
   d6d123403..ee501234a  master                -> origin/master

And after this fetch whenever I run

git rebase master

console returns

Current branch feature/PROJCT-1234 is up to date.

But if I run

git rebase origin/master

The rebase complete its job.

So the question is. To avoid to type origin/... each time. Is there a way to git fetch origin and have all branches with updates, ... pulled down?

Upvotes: 1

Views: 1644

Answers (2)

Marek R
Marek R

Reputation: 37697

If you are on master which you want to update, just do:

git pull
#or
git pull -r

if you want update master when working on other branch do:

git fetch origin master:master

There is no straight way to update all local branches. Rationale is simple: you should be able to check what has been fetched from remote repository. Any local branch updates should be performed only on your aware request, to avoid confusion.

Upvotes: 3

sashok_bg
sashok_bg

Reputation: 2971

You just do a merge origin/master is just another branch like master.

git fetch will update origin/master and afterwards you do git merge (or rebase) onto master

So in short

// sitting on master
git fetch

//useful to inspect changes before actually applying
git diff origin/master 

git merge origin/master

Alternatively a shortcut for the above fetch / merge is the pull. Beware though there is a trap since fetch merges origin/master onto master and if it is not a fastforwad merge, you will get an awkward merge from master to master in your history.

https://git-scm.com/docs/git-merge#_fast_forward_merge

You can find a good lecture on what actually a branch is here -> https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Once you realize it is just a pointer, things get a lot more clearer imo.

Cheers !

Upvotes: 1

Related Questions