问题
When I push a local working directory to a central repository, do all intermediate branches and commit information (from last push to this one) get pushed?
In other words, does push produce an exact replica of the entire history of my current working directory, including commits, branches, etc., and thus are made available to any other user pulling from the central repository?
If not everything is pushed, what gets excluded?
回答1:
When you run git push
, you can set what gets pushed on the command line. For example, this
git push origin my-branch:fooo
pushes branch "my-branch" from your local repository to branch "fooo" at "origin".
When you run git push
without any arguments, it pushes to remote set for your current branch (you can see that by git config branch.<branchname>.remote
) and does what is configured in push.default
configuration value, which, according to docs, can be one of the following:
nothing
- do not push anything.matching
- push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.upstream
- push the current branch to its upstream branch.tracking
- deprecated synonym for upstream.current
- push the current branch to a branch of the same name.
回答2:
It pushes the branches that you have configured to for that remote repository. Have a look at the config file .git/config
to see what has been configured.
If you want to see what will push use
git remote show origin
where you replace origin with the name of your remote repository. This shows what branches will push to that repo, and what the current state of the branches are.
回答3:
To complete the other answers, don't forget that git push
usually deals with branches (refs/heads
).
- It won't push tags, unless you specify
--tags
(or--mirror
), in which caserefs/tags
are pushed. - It won't push notes (often forgotten) unless you specify that ref namespace explicitly.
来源:https://stackoverflow.com/questions/6611385/git-push-clarification-what-gets-pushed