Git-subrepo: Add ability to switch to another subrepo branch (git subrepo clone -f) without repository url.

Created on 16 Jan 2018  路  9Comments  路  Source: ingydotnet/git-subrepo

Discussed in #328

User may be allowed to switch branch (or re-clone current branch) from the subrepo repository and throw all changes in project repository. Currently man may use git subrepo clone command but it requires to re-type subrepo url. There should be a possibility to reclone the branch withou the need to re-type the url - at least when git clone is used with '-f' switch. So the url may be optional or there should be another way to reclone branch.

Enhancement

Most helpful comment

There is a little "Catch 22" with the clone command. It uses the repo to guess the subdir and we would need the subdir to find the .gitrepo file :-) As the clone command runs without knowing which subrepo to interact with.

git subrepo checkout <path-to-sub> <other-branch> seems like it would be an ok solution with -b to create a new branch.

All 9 comments

This would be a nice feature

Agreed. This is what bothers me right now.
Something like
git subrepo <path-to-sub> checkout <other-branch>
and
git subrepo <path-to-sub> checkout -b <new-branch>

Very important for me, too!

There is a little "Catch 22" with the clone command. It uses the repo to guess the subdir and we would need the subdir to find the .gitrepo file :-) As the clone command runs without knowing which subrepo to interact with.

git subrepo checkout <path-to-sub> <other-branch> seems like it would be an ok solution with -b to create a new branch.

Is there a plan to fix this issue in future roadmap?

Hi. As an experiment I added subrepo reset (#489)
git subrepo reset <subdir> -b <branch>
This allows you to set the subrepo to a specific branch or even to a commit. Although it doesn't check if the commit resides on the branch....

git subrepo pull -b will already let you select a branch/commit. I change branches all the time. The pull --force feature says it behaves the way you describe, but is currently broken. I am planning to fix the --force feature unless I can be convinced otherwise.

Thanks @admorgan for pointing it out. I didn't know subrepo pull could do the job.
When I want to switch to a commit do I have to specify the full SHA or can I use a commit-ish reference?

Hi @admorgan, is the --force option working? I try to change branches using the pull but I get the error.

git-subrepo: Local repository does not contain 148426efe0d6b1b0c19976dcfe6e80bc59dcaf01. Try to 'git subrepo fetch module' or add the '-F' flag to always fetch the latest content.

How can I change branches without cloning?

Thanks!

@nmunozsi For me this was caused by the fact that my subrepo branch was some commits behind master, but the updated master was already pulled into my subrepo folder. To solve this I just rebased my branch in the original repo and after that I was able to pull (even without --force) the branch into my subrepo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

csteinlehner picture csteinlehner  路  12Comments

hassec picture hassec  路  5Comments

psorowka picture psorowka  路  5Comments

danielbsig picture danielbsig  路  7Comments

robe070 picture robe070  路  10Comments