default set of “refspec” for “git push”

Before this, I thought the effect of git fetch and git push on $GIT_DIR/config are the same, because both are commands for repository engagements but when we add a repository as remote repository for current repository, Git creates a default set of refspec for git fetch in config, for example like this:

fetch = +refs/heads/*:refs/remotes/remote_repository/*

Why does not do the same for default set of refspec for git push in config file?

  • git reset vs git reset HEAD
  • Git repository from github empty green folder
  • Coder collaboration best practices using Git
  • What does git merge origin branchname do?
  • Way to search source in Gitolite repos?
  • Label Git repository in AppVeyor build using environment variable
  • I guess difference is caused by default purpose of commands:

    • Default purpose offetch is for downloading all objects and refs from another repository
    • Default purpose ofpush is updating specific remote refs along with associated objects

    But I am not sure in about my guess. Is it true?

  • How do I rename the .git directory?
  • Git blame with wildcard
  • How to get what changes were made in what files as part of git commit?
  • Git tracking branches
  • git cherry pick - range of commits and exclude some in between
  • How do I fetch/clone only a few branches using git-svn?
  • 2 Solutions collect form web for “default set of “refspec” for “git push””

    Simply put, a branch can pull from one remote tracking branch and push to another.

    Even if you set a default push policy (git config push.default), that would be overridden by a local branch.<name>.push config.

    Since git 2.5, you can differentiate easily between the refspec used for fetch and push (if there is no push refspec for a branch, it defaults to the fetch one)

    For instance, if you are on your master branch and want to see if you are ahead or behind compare to the remote tracking branch you are pushing to (by default, origin/master, but it could be any other remote one if branch.master.push is set in the config)

    git for-each-ref --format="%(push:track)" refs/heads

    The shortcut <branch>@{push} refers directly to the value set in the config branch.master.push.

    For instance, to see the commits you haven’t pushed yet:

    git log @{push}..

    git push is working a bit different.

    You can set the push.default parameter to control it.

    Here is the git v2.0 release notes which explain the change in the way git treat push (simple vs matching). This was updated in git v2.0 to fix the default git push behaviour.

    Prior to git v2.0 when you executed git push it would have pushed all your changed branches (all and not only the current branch).

    Git v2.0 Release Notes

    Backward compatibility notes

    When git push [$there] does not say what to push, we have used the
    traditional matching semantics so far (all your branches were sent
    to the remote as long as there already are branches of the same name
    over there). In Git 2.0, the default is now the simple semantics,
    which pushes:

    • only the current branch to the branch with the same name, and only
      when the current branch is set to integrate with that remote
      branch, if you are pushing to the same remote as you fetch from; or

    • only the current branch to the branch with the same name, if you
      are pushing to a remote that is not where you usually fetch from.

    You can use the configuration variable push.default to change
    this. If you are an old-timer who wants to keep using the
    matching semantics, you can set the variable to matching, for
    example. Read the documentation for other possibilities.

    Git Baby is a git and github fan, let's start git clone.