问题
Sorry if this question has been asked already.
Am cloning from a repo named "git_lab" which has a branch named "test" When cloning i use "-b myname_test" to create a local branch named "myname_test" and local clone is named "myname_git_lab"
When i do "git pull" it automatically fetches and merges changes from "test" to "myname_test", but for git push, i need to specify the repo and branch name.
$>git remote show git_lab
Local branch configured for 'git pull': myname_test merges with remote test
Is there a way where i can configure "local branch configured for 'git push'" so that i dont need to specify the branch and repo name?
回答1:
There are two things you can do here.
Set
push.default
totracking
, so that it will push all branches to the remote branches they track, not the ones they have the same name as, then configure your branch with appropriate tracking information. (e.g. setbranch.master.remote
toorigin
andbranch.master.merge
torefs/heads/foo
.)Push manually.
git push origin master:foo
will push your localmaster
branch to the branchfoo
on the remoteorigin
.
However, I'd suggest that what you really want to do is just make the branch names the same.
(You can set config parameters either with git config
, e.g. git config push.default tracking
, or by directly editing the .git/config file.)
回答2:
git checkout --track origin/branchname
Alternatively, you can edit the config file in the .git folder.
来源:https://stackoverflow.com/questions/4109136/configure-a-local-branch-for-push-to-specific-branch