Synchronizing with Remote Repositories

Synchronizing the states of local and remote repositories involves Pulling from, and Pushing to, remote repositories. SmartGit also has a Synchronize command that combines pulling and pushing.

Pull

The Pull command fetches commits from a remote repository, stores them in the remote branches, and optionally ‘integrates’ these commits (i.e. by fast-forwarding, or by adding merge or rebase commits) into the local branch, depending on the nature of divergence of the branches, and the configured preference for merge types.

Use Remote -> Pull (or the corresponding toolbar button) to invoke the Pull command. For repositories with submodules, see Pulling on the outer repository.

Working Tree or Log window

If neither merge nor rebase has been configured yet for the repository, SmartGit first shows Configure Pull. There, choose Rebase or Merge. Use Remember as default for other repositories if the choice should also become the default for future repositories.

The Pull dialog lets you specify where commits should be fetched from and whether or how to integrate them:

  • If multiple remotes are configured, SmartGit allows you to either Fetch from all remotes or select the remote from which to fetch.
  • Click More Options to customize fetching and integration:
    • If you choose Pull and a fast-forward is not possible, choose whether to Merge the local commits with the fetched commits, or Rebase the local commits onto the fetched commits.
    • Update existing and fetch new tags fetches all remote tags and can replace existing local tags with their remote versions.
    • Remember as default for repository saves these choices. Additional options are available in the Repository Settings.

Fetch Only also uses the tag and Remember as default for repository choices.

The Pull Dialog has 3 buttons:

  • Pull - will perform the pull in accordance with the above preferences.
  • Fetch Only - fetches from the selected remote or all remotes, without integrating changes into the local branch.
  • Cancel - closes the dialog without changes.

If the current branch does not track a compatible branch of the selected remote, SmartGit disables the Pull option, but you can still use Fetch Only to download commits from other branches.

With Fetch from all remotes selected, SmartGit fetches each remote separately. Pull then integrates the current branch with its tracked branch. Fetch errors do not undo refs already updated. If at least one remote fetch completes, SmartGit can proceed despite fetch errors from other remotes.

Select a remote in the Branches view and invoke Fetch to fetch it directly. This uses the saved tag-update choice without opening the Pull dialog.

Note

Clearing Update existing and fetch new tags does not override a remote’s remote.<name>.tagopt=--tags setting. Clearing Prune obsolete remote tracked branches in Repository Settings stops SmartGit from requesting pruning. Git’s own pruning configuration can still apply.

Note

Saving Merge as the repository default writes pull.rebase=false and removes the current branch’s branch.<name>.rebase override.

To pull from a repository selection, select one or more repositories in the Repositories view and choose Remote -> Pull. The selected repositories do not need to be open first.

Standard window

In the Standard Window, Pull uses the Repository Settings without opening the Pull dialog. Commit or stash local changes, including untracked files, before pulling. This command does not automatically stash local changes.

Open the Pull toolbar button’s popup to choose Fetch without integrating local branches. For multiple remotes, the popup also offers commands to fetch a specific remote or Fetch All. Select Pull from all remotes to fetch them all before integrating the current branch.

If Pull detects a local rewrite of the tracked branch, it offers Fetch Only or Re-integrate. Both choices fetch only the current branch’s remote, even if Pull from all remotes is selected.

After fetching, Pull can update other local branches without checking them out. It can fast-forward a branch when the fetched history contains its local commits. If the branch matched its tracked branch before fetching, it can also follow rewritten remote history. Branches that had already diverged, or are checked out in another worktree, are skipped.

Pull stops at the first fetch error, before updating or integrating local branches.

Note

Set the Low-Level Property standard.pull.allowDirtyWt to true to allow pulling with local changes in the Standard Window. Automatic stash recovery remains unavailable.

Pulling

If a merge or rebase is performed after pulling, it may fail due to conflicting changes. In that case SmartGit will leave the repository in a merging or rebasing state so you can either resolve the conflicts and proceed, or abort the operation. See Merge, Rebase, and the SmartGit Conflict Solver for details.

When rebasing, SmartGit will detect whether there are local merge commits which have to be rebased and in this case ask you whether you want to “preserve” these merge commits during the rebase or flatten the merge commits.

Pull with Merge in the Log and Working Tree windows first tries integration with local changes in place. If integration fails and stash recovery is available, SmartGit can save local changes in a stash and retry the merge. Afterward, it tries to restore the changes and their staging state. See the automatic stash preferences for confirmation and untracked-file options. If your changes remain stashed during conflict resolution, finish the merge before applying the stash.

Pulled vs. Fetched vs. Remote-Repository-Only Commits

Depending on the relative state of the local repository/working tree and the remote, three kinds of commits can be distinguished:

  • Remote-Repository-Only commits: These are commits not yet present in your local repository. SmartGit will denote such kind of “incoming” commits by displaying a green arrow for the repository’s node in the Repositories view if Detect remote changes has been selected in the Preferences -> Background commands setting. To detect such commits, SmartGit uses a git ls-remote which is a light-weight operation which only reports remote repository branches together with their remote commit SHA. If the SHA is not yet present in the local repository for a specific branch, it is considered to have “incoming” commits. SmartGit does not have more information on these commits, not even the number of “incoming” commits. If you want to know more details about these commits and/or investigate them, it’s usually safe to fetch them using Remote -> Pull with Fetch Only option.
  • Fetched commits: are already present in the local repository, but not yet part of your HEAD’s history. You can see and investigate these commits in the Log and perform various operations on them, e.g., Merge, Rebase onto a commit, or Reset your HEAD onto such a commit.
  • Pulled commits: are part of your HEAD’s history and their contents are present in your working tree.

Push

The various Push commands allow you to push (i.e. send) your local commits to one or more remote repositories. SmartGit distinguishes between the following Push commands:

  • Push pushes all commits of the current branch (or the selected branch in the Branches view) to its tracked branch(es) on the remote(s). In the Log and Working Tree windows, Push can target multiple remotes in a single action. SmartGit will detect automatically whether a forced push will be necessary. Push is available from any SmartGit Window (Working Tree, Standard, and Log).
  • Push To pushes all commits in the current branch either to its matching branch, or to a ref specified by name. With the Push To command you can only push to one remote repository at a time. If multiple remote repositories have been tracked by your local repository, the Push To dialog will allow you to select the remote repository to push to. The pushed-history preference controls whether Push To offers a forced push after changing history, for example through Rebase. This is necessary when pushing to a secondary remote repository for which forcing the push may be necessary while it is not when pushing to the primary remote repository (i.e. the one which is considered by SmartGit’s forced push detection). In the Log and Working Tree windows, you can also invoke Push To on a remote to push (or synchronize) all branches from the selected remote to another remote.
  • Push Up To (in the Graph or Journal Views) pushes all new commits up to, and including, the selected commit, rather than all commits, in the current branch to its tracked remote branch.

When you invoke Push To for a single local branch, the dialog can show Push To options for Tracked or matching branch and Custom Ref. Use Custom Ref if the target name should differ from the tracked branch or if you need to push to a non-standard Git ref. If multiple remotes exist, choose the Target Repository first. The dialog can also offer Force pushing (even if it’s not fast-forward). A forced branch push checks that the remote branch is still at its expected commit. A forced Push To for a tag can overwrite the target tag without this check.

When you invoke Push To on a remote in the Branches view of the Log or Working Tree window, SmartGit pushes its locally known branches to another remote. Fetch the source remote first if these refs may be outdated. The Push all tags preference does not apply to this operation.

That dialog can also offer Force pushing (even if it’s not fast-forward) and Remove remote branches which don’t have a local counterpart. The latter removes target branches that have no corresponding locally known source-remote branch. Both options are dangerous because they rewrite or delete refs on the target remote. Use them only if the target remote is intended to mirror the source remote.

In the Log and Working Tree windows, pushing a new local branch can ask whether to set up tracking for the newly created remote branch. In most cases it is recommended to set up tracking, as it will allow you to receive changes from the remote repository and make use of Git’s branch synchronization mechanism (see Branches). The preferences contain an option to avoid this dialog and always configure the tracking.

Note

In the Log and Working Tree windows, tracking is not configured when push.default=matching.

In the Standard Window, Push targets a single remote. A valid remote.pushDefault setting takes priority over the remote detected for the branch. For a branch without tracking, SmartGit pushes to a same-name remote branch and configures tracking. If a locally known remote branch already has that name at a different commit, Push stops.

The Push commands listed above can be invoked from several places:

  • Menu and toolbar In the menu, you can invoke the various Pull and Push commands with Remote -> Pull, Remote -> Push, Remote -> Push To, and Remote -> Push Commits. Remote -> Push and Remote -> Push To may also be available as toolbar buttons, depending on your toolbar configuration. Remote -> Push Commits is only enabled if the Journal view is focused.
  • Repositories view You can invoke Push in the Repositories view by selecting the open repository and choosing Push from the context menu.
  • Branches view In the context menu of the Branches view, you can invoke Push and Push To on local branches. Additionally, you can invoke Push on tags.
  • Journal view To push a range of commits up to a certain commit, select that commit in the Journal view and invoke Push Commits from the context menu.

Note

With Push or Push To for a branch or tag, rejected refs can cause a failure even if other refs have already been updated on the remote.

Note

Set the Low-Level Property push.requestPrePushHookConfirmation to true to ask whether to run a detected pre-push hook. Choose Run Hook or Skip Hook.

Note

If a Push fails with error:

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

you have tried to push to a non-bare repository (a repository which has a working tree). Please either switch the remote to a different branch or – better – only push to bare repositories (repositories without a working tree).

To create a bare repository, please invoke

$ git init --bare path/to/repository

Synchronize

With the Synchronize command, you can push local commits to a remote repository and pull commits from that repository at the same time. This simplifies the common workflow of separately invoking Push and Pull to keep your repository synchronized with the remote repository.

The Synchronize command can be invoked as follows:

  • from the menu via Remote -> Synchronize,
  • with the Synchronize toolbar button,
  • and in the Repositories view via Synchronize in the repository’s context menu.

From the toolbar button’s options menu, you can configure whether to push or to pull first.

Push, then Pull

If there are both local and remote commits, the invoked push operation fails. The pull operation on the other hand is performed even in case of failure, so that the commits from the remote repository are available in the tracked branch, ready to be merged or rebased. After the remote changes have been applied to the local branch, you may invoke the Synchronize command again.

Pull, then Push

If there are both local and remote commits, the first triggered pull will fetch the remote changes, merge your local changes or rebase your local commits on top of the remote commits and, if this was successful, invokes the push. This has the advantage that if there were no conflicts all your local changes are pushed. The disadvantage is that it may push untested changes.

  • git fetch: --prune, --tags, --no-tags, --force.
  • git merge --ff <tracked-branch>, optionally with --no-commit.
  • git rebase: --fork-point, --rebase-merges=rebase-cousins.
  • git push: --tags, --prune, --force-with-lease, --force.
  • git stash push: --include-untracked.
  • git stash pop --index <stash>.
  • git config gui.pruneduringfetch.
  • git config smartgit.fetch.tags.
  • git config remote.<name>.tagopt.
  • git config smartgit.pullAll.
  • git config pull.rebase.
  • git config branch.<name>.rebase.
  • git config remote.pushDefault.
  • git config push.recurseSubmodules.