简体   繁体   English

如何从远程仓库创建本地私有 git 分支?

[英]How to create local private git branch from a remote repo?

I am from perforce background.我来自 perforce 背景。 Now I have moved to a new team where we are using GIT and I use a Windows 7 box.现在我搬到了一个使用 GIT 的新团队,我使用的是 Windows 7 机器。

As per our branching strategy we create a new branch for every feature from a branch called 'develop'.根据我们的分支策略,我们为名为“develop”的分支中的每个功能创建一个新分支。 So for us develop is like the trunk in perforce/svn from where I would like to keep merging into local branch at regular interval.所以对我们来说,开发就像 perforce/svn 中的主干,我想定期合并到本地分支。

This is I what I am trying to achieve: Create my private branch, say 'develop-user-private'.这就是我想要实现的目标:创建我的私有分支,比如“开发用户私有”。 Being in a new team I will do a lot of research(dummy code changes to understand the application logic while debugging) in this branch.在一个新团队中,我将在这个分支中做很多研究(虚拟代码更改以在调试时理解应用程序逻辑)。 Therefore, I will not push anything back to server but only commit to local repo.因此,我不会将任何内容推送回服务器,而只会提交到本地存储库。 I only want this branch on my local machine but do not want it on server, I mean only a private local branch.我只希望在我的本地机器上有这个分支,但不希望在服务器上有它,我的意思是只有一个私有的本地分支。

This is what I did这就是我所做的

cd c:\\GitRepo cd c:\\GitRepo

git init混帐初始化

git clone https://user@gitrepourl git 克隆https://user@gitrepourl

Upto this it looks good based on the readings I have done.到目前为止,根据我所做的阅读,它看起来不错。 Now when I run现在当我跑

git branch develop-user-private git 分支开发-用户-私有

it fails with error它因错误而失败

"fatal: Not a valid object name: 'master' " “致命:不是有效的对象名称:'master'”

Questions:问题:

  1. How to create this local private branch from 'develop'?如何从“开发”创建这个本地私有分支?

  2. What will be the command to take(merge) latest from 'develop' into this new branch?从“开发”中获取(合并)最新到这个新分支的命令是什么?

Git will not create a master branch until you commit something.在你提交一些东西之前, Git不会创建一个 master 分支。 As suggested in the comments, init is not required when cloning.正如评论中所建议的,克隆时不需要init

  1. Clone the repository: `git clone https://user@gitserver ...克隆存储库:`git clone https://user@gitserver ...
  2. Change to repository: cd <repository-name>更改到存储库: cd <repository-name>
  3. Create a local branch: git branch <local-branch-name>创建本地分支: git branch <local-branch-name>
  4. Do all the adds/edits you want to do and commit the changes: git commit -am "commit message"做所有你想做的添加/编辑并提交更改: git commit -am "commit message"
  5. Go back to master branch: git checkout master回到 master 分支: git checkout master
  6. Do a pull on master: git pull origin master在 master 上拉一下: git pull origin master
  7. Merge your local-branch into master: git merge <local-branch-name>将您的本地分支合并到主分支: git merge <local-branch-name>
  8. Push to origin master branch: git push origin master推送到 origin master 分支: git push origin master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM