Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
774 views
in Technique[技术] by (71.8m points)

git - Configure a local branch for push to specific branch

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two things you can do here.

  • Set push.default to tracking, 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. set branch.master.remote to origin and branch.master.merge to refs/heads/foo.)

  • Push manually. git push origin master:foo will push your local master branch to the branch foo on the remote origin.

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...