Skip to content

git update

Felipe Contreras edited this page May 10, 2014 · 1 revision

git-update(1)

NAME

git-update - update the current branch to the latest remote status

SYNOPSIS

git update [options]

DESCRIPTION

Incorporates changes from a remote repository into the current branch.

git update runs git fetch and then tries to update the current branch to the latest status. If you don’t have any extra changes, the update operation is straight-forward, but if you do have them, extra actions are necessary.

Assume the following history exists and the current branch is "master":

	 A---B---C origin/master
	/
    D---E master

Then git update will merge in a fast-foward way up to the new master.

    D---E---A---B---C master, origin/master

owever, a non-fast-foward case looks very different.

	 A---B---C origin/master
	/
    D---E---F---G master

This divergence means master cannot be fast-forwarded to origin/master and that is named a "non-fast-forward". By default git update will warn about these situations, however, most likely you would want a merge, which you can force with git update --merge. This will result in a new commit that combines the tips of both branches (C and G). See linkgit:git-merge[1] for more details.

	   origin/master
		 |
	 A---B---C---H master
	/           /
    D---E---F------G

You can choose to do a rebase instead by specifying the --rebase option, which is slightly more complicated, but results in a cleaner history. In this mode the commits that are not present in the remote branch are replayed on top of it, which results in newer commits. See linkgit:git-rebase[1] for more details.

		      F---G master
		     /
    D---E---A---B---C origin/master

You should make sure you don’t have any uncommitted changes before running git update. It is generally best to get any local changes in working order before pulling or stash them away with linkgit:git-stash[1].

The remote branch

By default git update will try to use the origin remote and a branch with the same name as the current branch. So if you are currently in the topic branch, git update will try to incorporate the changes from origin/topic.

If you have configured an upstream tracking branch (e.g. git branch --set-upstream-to), then that branch will be used instead of the default. To find out the upstream of your current branch, you can run git name-rev @{upstream}.

OPTIONS

-q
--quiet

Be quiet.

-v
--verbose

Be verbose.

--[no-]recurse-submodules[=yes|on-demand|no]

This option controls if new commits of all populated submodules should be fetched too (see linkgit:git-config[1] and linkgit:gitmodules[5]). That might be necessary to get the data needed for merging submodule commits. Notice that the result of a merge will not be checked out in the submodule, "git submodule update" has to be called afterwards to bring the work tree up to date with the merge result.

-r
--rebase[=false|true|preserve]

When true, rebase the current branch on top of the remote branch after fetching.

When preserve, also rebase the current branch on top of the upstream branch, but pass --preserve-merges along to git rebase so that locally created merge commits will not be flattened.

When false, merge the current branch into the upstream branch.

See update.mode, branch.<name>.updatemode and branch.autosetuprebase in linkgit:git-config[1] if you want to make git update always use --rebase.

Note
This is a potentially dangerous mode of operation. It rewrites history, which does not bode well when you published that history already. Do not use this option unless you have read linkgit:git-rebase[1] carefully.
-m
--merge

Force a merge.

See update.mode, branch.<name>.updatemode in linkgit:git-config[1] if you want to make git update always use --merge.

BUGS

Using --recurse-submodules can only fetch new commits in already checked out submodules right now. When e.g. upstream added a new submodule in the just fetched commits of the superproject the submodule itself can not be fetched, making it impossible to check out that submodule later without having to do a fetch again. This is expected to be fixed in a future Git version.

SEE ALSO

linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-rebase[1], linkgit:git-config[1]

GIT

Part of the linkgit:git[1] suite

Clone this wiki locally