e271p314
e271p314

Reputation: 4029

When do I need to run "git pull --all"?

In order to know when I need to run git pull --all I run git rev-parse origin/<branch name> and git ls-remote | grep <branch name> if the SHA of the branch I got from rev-parse is different from the the SHA I got from ls-remote I know that I need to run git pull --all.

Today, I saw a problem with this idea, after I added a new branch to the git repository and run git rev-parse origin/<new branch name> I got unknown revision or path not in the working tree. Any idea how to know when I need to run git pull --all and support the case when I add new branches? In short, how to know if a new branch was add to the git repository?

Upvotes: 1

Views: 1506

Answers (1)

poke
poke

Reputation: 387537

Usually, you would never need to run git pull --all at all. With Git, you are always working on a single branch, so at any time, the current branch will be the only one you need to care about. Often, it’s even encouraged to keep your local branch outdated, so you can continue working without having to worry about upstream changes which might introduce changed features (that would impact your own current work), or even result in merge conflicts.

So usually, you would only run git pull for the current branch, if you actually want to update your current branch.

Another thing is fetching. Fetching, using git fetch, will update all your remote branches, receiving all changes from the remote repository and storing them in origin/branch branches (those are called remote branches because they belong to the remote). That way, you can update your local representation of the remote repository, making all its changes available to you. This will however not merge those changes into your local branches, so you still have full control over when and what to merge.

So if you want to have some information about what’s going on on the remote repository, you can regularly call git fetch to update your remote branches. This will always work and update whatever the remote has to offer—at worst, it will just tell you that there’s nothing new. It will also tell you which remote branches were updated, and when new branches were added, so that’s a good indicator for activity too.

And when you then decide that you really want to pull in the remote changes into your local branch, you can either run git pull (which internally fetches again for the current branch and then performs a merge), or just do git merge origin/branchname to merge the previously fetched changes manually into your local branch.

Upvotes: 2

Related Questions