I'm just getting started with git and I have a question. My app has 10 other developers working on it, each one having their own branch like dev_XXXXX. So if I do a clone of the repository, do all of their code gets copied to my machine? In that case I dont want that. Suppose my branch is dev_swamy, how do I then clone just the stable branch and dev_swamy? Thanks.
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Another way to do this is to avoid a direct clone, but instead manually add a remote with a custom set of fetch refspecs.
e.g.
If you clone, all revisions in all branches are cloned along, but the cloned repository will check out master by default.
Just taking selected branches is trickier since git does not really think you should work that way. You have to pull down the branches manually:
Above is what I knew worked. However, if you want to set up a git repo that works as normal, just has a more narrow view of its remote branches? You can do that pretty easily:
I think the more important question here is what others will be pushing, not what you will be cloning or pulling. Since each developer is working on his own branch, another question is how you end up with a common code base. Are the developers merging their branches to master? And are they then pushing their changed master branch to a central repository? If that is the case, there is no way for you to pull the other developers' branches anyway.
If that is not the case, I fail to see how you can form a functioning team.
And as I final thought: I'd be curious to know why you wouldn't want to clone the other developers' branches to your repository?
By default
git clone
would fetch all branches, but those branches would be stored as remote-tracking branches: for example branch 'dev_XXXXX' would be stored as 'origin/dev_XXXXX' (with 'refs/remotes/origin/dev_XXXXX' as full name). Those remote-tracking branches wouldn't be visible ingit branch
output: you would needgit branch -r
to list remote-tracking branches (orgit branch -a
to list all branches). If those branches do not diverge too much from mainline, they wouldn't take too much disk space in repository. Therefore I don't see why you want to clone only selected branches.Nevertheless if you want to have a clone with only two selected branches, you can do it like this:
First, create new empty repository
Then add your repository under the name 'origin' (just like "git clone" would name it), requesting tracking of only two branches: 'master' and 'dev_swamy', using "git remote" command. Check that it was added correctly.
If the stable branch is called 'stable' rather than 'master', you would have of course to modify above example. Also there is
-m <branch>
option if you want specified branch to be default branch in remote.Fetch from 'origin' (you could do this also by using
-f
option to "git remote add" above):Set up local branch 'master' (where you would do your work) to follow 'origin/master' (to have 'origin/master' as upstream), just like "git clone" would do:
You can repeat this for branch 'dev_swamy'.
Now you can see how config file looks like. You can get exactly the same result by editing
.git/config
file to look like the following, and then doing "git fetch".Don't forget to introduce yourself to Git before starting work on repository (i.e. set 'user.name' and 'user.email' config variables; usually in per-user config file)!