Rename a git submodule
Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).
And while we are at it, why is it that I simply cannot do the following in the parent directory: git mv old-submodule-name new-submodule-name
git git-submodules
add a comment |
Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).
And while we are at it, why is it that I simply cannot do the following in the parent directory: git mv old-submodule-name new-submodule-name
git git-submodules
4
You will no longer need to update.gitmodules
manually when moving a submodule. see my answer below
– VonC
Sep 10 '13 at 7:17
@VonC's answer worked like a charm for me
– laconbass
May 23 '15 at 3:31
Git modules are too complicated.npm
shows how simple works. One day... maybe... someone... will rewrite it... in the meantime...
– Rolf
Mar 18 '18 at 15:00
@VonC's answer is not the full story as of today: it will indeed change .gitmodules, but will just rename the path, not the module name. You need an additional edit to .gitmodules to correct that and a 'git submodule sync' to complete the full process
– zertyz
Dec 7 '18 at 22:06
add a comment |
Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).
And while we are at it, why is it that I simply cannot do the following in the parent directory: git mv old-submodule-name new-submodule-name
git git-submodules
Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).
And while we are at it, why is it that I simply cannot do the following in the parent directory: git mv old-submodule-name new-submodule-name
git git-submodules
git git-submodules
edited May 23 '17 at 11:33
Community♦
11
11
asked Dec 24 '10 at 14:52
Lars TackmannLars Tackmann
11k135474
11k135474
4
You will no longer need to update.gitmodules
manually when moving a submodule. see my answer below
– VonC
Sep 10 '13 at 7:17
@VonC's answer worked like a charm for me
– laconbass
May 23 '15 at 3:31
Git modules are too complicated.npm
shows how simple works. One day... maybe... someone... will rewrite it... in the meantime...
– Rolf
Mar 18 '18 at 15:00
@VonC's answer is not the full story as of today: it will indeed change .gitmodules, but will just rename the path, not the module name. You need an additional edit to .gitmodules to correct that and a 'git submodule sync' to complete the full process
– zertyz
Dec 7 '18 at 22:06
add a comment |
4
You will no longer need to update.gitmodules
manually when moving a submodule. see my answer below
– VonC
Sep 10 '13 at 7:17
@VonC's answer worked like a charm for me
– laconbass
May 23 '15 at 3:31
Git modules are too complicated.npm
shows how simple works. One day... maybe... someone... will rewrite it... in the meantime...
– Rolf
Mar 18 '18 at 15:00
@VonC's answer is not the full story as of today: it will indeed change .gitmodules, but will just rename the path, not the module name. You need an additional edit to .gitmodules to correct that and a 'git submodule sync' to complete the full process
– zertyz
Dec 7 '18 at 22:06
4
4
You will no longer need to update
.gitmodules
manually when moving a submodule. see my answer below– VonC
Sep 10 '13 at 7:17
You will no longer need to update
.gitmodules
manually when moving a submodule. see my answer below– VonC
Sep 10 '13 at 7:17
@VonC's answer worked like a charm for me
– laconbass
May 23 '15 at 3:31
@VonC's answer worked like a charm for me
– laconbass
May 23 '15 at 3:31
Git modules are too complicated.
npm
shows how simple works. One day... maybe... someone... will rewrite it... in the meantime...– Rolf
Mar 18 '18 at 15:00
Git modules are too complicated.
npm
shows how simple works. One day... maybe... someone... will rewrite it... in the meantime...– Rolf
Mar 18 '18 at 15:00
@VonC's answer is not the full story as of today: it will indeed change .gitmodules, but will just rename the path, not the module name. You need an additional edit to .gitmodules to correct that and a 'git submodule sync' to complete the full process
– zertyz
Dec 7 '18 at 22:06
@VonC's answer is not the full story as of today: it will indeed change .gitmodules, but will just rename the path, not the module name. You need an additional edit to .gitmodules to correct that and a 'git submodule sync' to complete the full process
– zertyz
Dec 7 '18 at 22:06
add a comment |
7 Answers
7
active
oldest
votes
I found following workflow working:
- Update .gitmodules
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.
22
note to self: forgit add newpath
don't use a trailing slash
– atomicules
Jul 28 '11 at 15:17
1
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
10
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
5
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
2
If you do have the problem with the working tree, you can also edit the.git/modules/SUBMODULE/config
file, such that theworktree
points to the the right directory again.
– Vincent Ketelaars
Apr 10 '14 at 14:24
|
show 6 more comments
Git1.8.5 (October 2013) should simplify the process. Simply do a:
git mv A B
"
git mv A B
", when moving a submoduleA
has been taught to relocate its working tree and to adjust the paths in the.gitmodules
file.
See more in commit 0656781fadca1:
Currently using "
git mv
" on a submodule moves the submodule's work tree in that of the superproject. But the submodule's path setting in.gitmodules
is left untouched, which is now inconsistent with the work tree and makes git commands that rely on the properpath -> name mapping
(likestatus
anddiff
) behave strangely.
Let "
git mv
" help here by not only moving the submodule's work tree but also updating the "submodule.<submodule name>.path
" setting from the.gitmodules
file and stage both.
This doesn't happen when no.gitmodules
file is found and only issues a warning when it doesn't have a section for this submodule. This is because the user might just use plain gitlinks without the.gitmodules
file or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him thatmv
would have done that for him).
Only when.gitmodules
is found and contains merge conflicts themv
command will fail and tell the user to resolve the conflict before trying again.
git 2.9 (June 2016) will improve git mv
for submodule:
See commit a127331 (19 Apr 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 9cb50a3, 29 Apr 2016)
mv
: allow moving nested submodules
"
git mv old new
" did not adjust the path for a submodule that lives as a subdirectory insideold/
directory correctly.
submodules however need to update their link to the git directory as
well as updates to the.gitmodules
file.
Note to self: Try this on 1.8.4 and you will havefatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.
– checksum
Nov 29 '13 at 2:22
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
2
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
5
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
|
show 22 more comments
$ mv submodule-oldpath submodule-newpath
$ git rm submodule-oldpath
$ git add submodule-newpath
$ git submodule sync
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule.
the correct solution is:
$ mv submodule-oldpath ~/another-location
$ git rm submodule-oldpath
$ git submodule add submodule-repository-URL submodule-newpath
Source: http://bcachet.github.io/development/2012/05/25/rename-git-submodule/
2
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
add a comment |
I just tried a few of the suggested above. I'm running:
$ git --version
git version 1.8.4
I found it was best to de-init the submodule, remove the directory and create a new submodule.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
At least that is what worked for me best. YMMV!
add a comment |
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a git submodule sync
afterwards, but I'm not in a position to check right now.
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
1
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
add a comment |
It's not possible to rename it, so you've to remove it first (deinit
) and add it again.
So after removing it:
git submodule deinit <path>
git rm --cached <path>
you may also double check and remove the references to it in:
.gitmodules
.git/config
- remove reference folder from
.git/modules/<name>
(best to make a backup), as each folder hasconfig
file where it keeps the reference to itsworktree
then stage your changes by committing any changes to your repo by:
git commit -am 'Removing submodule.'
and double check if you don't have any outstanding issues by:
git submodule update
git submodule sync
git submodule status
so now you can add the git submodule again:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
also it is actually today
– Alexey
Oct 12 '18 at 12:53
add a comment |
MacOs: When I wanna use VonC solution to change submodule folder Common
to lowercase:
git mv Common common
I get
fatal: renaming 'Common' failed: Invalid argument
Solution - use some temporary folder name and move twice:
git mv Common commontemp
git mv commontemp common
That's all :)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4526910%2frename-a-git-submodule%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found following workflow working:
- Update .gitmodules
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.
22
note to self: forgit add newpath
don't use a trailing slash
– atomicules
Jul 28 '11 at 15:17
1
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
10
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
5
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
2
If you do have the problem with the working tree, you can also edit the.git/modules/SUBMODULE/config
file, such that theworktree
points to the the right directory again.
– Vincent Ketelaars
Apr 10 '14 at 14:24
|
show 6 more comments
I found following workflow working:
- Update .gitmodules
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.
22
note to self: forgit add newpath
don't use a trailing slash
– atomicules
Jul 28 '11 at 15:17
1
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
10
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
5
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
2
If you do have the problem with the working tree, you can also edit the.git/modules/SUBMODULE/config
file, such that theworktree
points to the the right directory again.
– Vincent Ketelaars
Apr 10 '14 at 14:24
|
show 6 more comments
I found following workflow working:
- Update .gitmodules
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.
I found following workflow working:
- Update .gitmodules
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.
edited Nov 15 '18 at 18:41
Nathan Arthur
3,03132448
3,03132448
answered Apr 4 '11 at 14:52
Mariusz NowakMariusz Nowak
23.8k32931
23.8k32931
22
note to self: forgit add newpath
don't use a trailing slash
– atomicules
Jul 28 '11 at 15:17
1
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
10
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
5
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
2
If you do have the problem with the working tree, you can also edit the.git/modules/SUBMODULE/config
file, such that theworktree
points to the the right directory again.
– Vincent Ketelaars
Apr 10 '14 at 14:24
|
show 6 more comments
22
note to self: forgit add newpath
don't use a trailing slash
– atomicules
Jul 28 '11 at 15:17
1
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
10
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
5
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
2
If you do have the problem with the working tree, you can also edit the.git/modules/SUBMODULE/config
file, such that theworktree
points to the the right directory again.
– Vincent Ketelaars
Apr 10 '14 at 14:24
22
22
note to self: for
git add newpath
don't use a trailing slash– atomicules
Jul 28 '11 at 15:17
note to self: for
git add newpath
don't use a trailing slash– atomicules
Jul 28 '11 at 15:17
1
1
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
this works for me and the submodule appears as renamed in the status output (git status) after the move.
– Lars Tackmann
Nov 9 '11 at 10:03
10
10
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
With such a workflow, you will only create a symlink to the sub-directory you use as a submodule. Symlink is just a part of the global submodule functionality. This mean that when you clone the repo that use the renamed submodules, you may end with the following error: No submodule mapping found in .gitmodules for path 'your-oldpath' After you remove the oldpath (*git rm oldpath), you should use git submodule add REPO-URL newpath instead of "git add newpath*. When done, git status will display something like this: renamed: oldpath -> newpath
– Bertrand
Jan 26 '12 at 9:45
5
5
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule. try $ mv submodule-oldpath ~/another-location $ git rm submodule-oldpath $ git submodule add submodule-repository-URL submodule-newpath bcachet.github.io/development/2012/05/25/rename-git-submodule
– Mahmoud Adam
May 6 '13 at 15:07
2
2
If you do have the problem with the working tree, you can also edit the
.git/modules/SUBMODULE/config
file, such that the worktree
points to the the right directory again.– Vincent Ketelaars
Apr 10 '14 at 14:24
If you do have the problem with the working tree, you can also edit the
.git/modules/SUBMODULE/config
file, such that the worktree
points to the the right directory again.– Vincent Ketelaars
Apr 10 '14 at 14:24
|
show 6 more comments
Git1.8.5 (October 2013) should simplify the process. Simply do a:
git mv A B
"
git mv A B
", when moving a submoduleA
has been taught to relocate its working tree and to adjust the paths in the.gitmodules
file.
See more in commit 0656781fadca1:
Currently using "
git mv
" on a submodule moves the submodule's work tree in that of the superproject. But the submodule's path setting in.gitmodules
is left untouched, which is now inconsistent with the work tree and makes git commands that rely on the properpath -> name mapping
(likestatus
anddiff
) behave strangely.
Let "
git mv
" help here by not only moving the submodule's work tree but also updating the "submodule.<submodule name>.path
" setting from the.gitmodules
file and stage both.
This doesn't happen when no.gitmodules
file is found and only issues a warning when it doesn't have a section for this submodule. This is because the user might just use plain gitlinks without the.gitmodules
file or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him thatmv
would have done that for him).
Only when.gitmodules
is found and contains merge conflicts themv
command will fail and tell the user to resolve the conflict before trying again.
git 2.9 (June 2016) will improve git mv
for submodule:
See commit a127331 (19 Apr 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 9cb50a3, 29 Apr 2016)
mv
: allow moving nested submodules
"
git mv old new
" did not adjust the path for a submodule that lives as a subdirectory insideold/
directory correctly.
submodules however need to update their link to the git directory as
well as updates to the.gitmodules
file.
Note to self: Try this on 1.8.4 and you will havefatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.
– checksum
Nov 29 '13 at 2:22
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
2
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
5
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
|
show 22 more comments
Git1.8.5 (October 2013) should simplify the process. Simply do a:
git mv A B
"
git mv A B
", when moving a submoduleA
has been taught to relocate its working tree and to adjust the paths in the.gitmodules
file.
See more in commit 0656781fadca1:
Currently using "
git mv
" on a submodule moves the submodule's work tree in that of the superproject. But the submodule's path setting in.gitmodules
is left untouched, which is now inconsistent with the work tree and makes git commands that rely on the properpath -> name mapping
(likestatus
anddiff
) behave strangely.
Let "
git mv
" help here by not only moving the submodule's work tree but also updating the "submodule.<submodule name>.path
" setting from the.gitmodules
file and stage both.
This doesn't happen when no.gitmodules
file is found and only issues a warning when it doesn't have a section for this submodule. This is because the user might just use plain gitlinks without the.gitmodules
file or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him thatmv
would have done that for him).
Only when.gitmodules
is found and contains merge conflicts themv
command will fail and tell the user to resolve the conflict before trying again.
git 2.9 (June 2016) will improve git mv
for submodule:
See commit a127331 (19 Apr 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 9cb50a3, 29 Apr 2016)
mv
: allow moving nested submodules
"
git mv old new
" did not adjust the path for a submodule that lives as a subdirectory insideold/
directory correctly.
submodules however need to update their link to the git directory as
well as updates to the.gitmodules
file.
Note to self: Try this on 1.8.4 and you will havefatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.
– checksum
Nov 29 '13 at 2:22
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
2
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
5
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
|
show 22 more comments
Git1.8.5 (October 2013) should simplify the process. Simply do a:
git mv A B
"
git mv A B
", when moving a submoduleA
has been taught to relocate its working tree and to adjust the paths in the.gitmodules
file.
See more in commit 0656781fadca1:
Currently using "
git mv
" on a submodule moves the submodule's work tree in that of the superproject. But the submodule's path setting in.gitmodules
is left untouched, which is now inconsistent with the work tree and makes git commands that rely on the properpath -> name mapping
(likestatus
anddiff
) behave strangely.
Let "
git mv
" help here by not only moving the submodule's work tree but also updating the "submodule.<submodule name>.path
" setting from the.gitmodules
file and stage both.
This doesn't happen when no.gitmodules
file is found and only issues a warning when it doesn't have a section for this submodule. This is because the user might just use plain gitlinks without the.gitmodules
file or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him thatmv
would have done that for him).
Only when.gitmodules
is found and contains merge conflicts themv
command will fail and tell the user to resolve the conflict before trying again.
git 2.9 (June 2016) will improve git mv
for submodule:
See commit a127331 (19 Apr 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 9cb50a3, 29 Apr 2016)
mv
: allow moving nested submodules
"
git mv old new
" did not adjust the path for a submodule that lives as a subdirectory insideold/
directory correctly.
submodules however need to update their link to the git directory as
well as updates to the.gitmodules
file.
Git1.8.5 (October 2013) should simplify the process. Simply do a:
git mv A B
"
git mv A B
", when moving a submoduleA
has been taught to relocate its working tree and to adjust the paths in the.gitmodules
file.
See more in commit 0656781fadca1:
Currently using "
git mv
" on a submodule moves the submodule's work tree in that of the superproject. But the submodule's path setting in.gitmodules
is left untouched, which is now inconsistent with the work tree and makes git commands that rely on the properpath -> name mapping
(likestatus
anddiff
) behave strangely.
Let "
git mv
" help here by not only moving the submodule's work tree but also updating the "submodule.<submodule name>.path
" setting from the.gitmodules
file and stage both.
This doesn't happen when no.gitmodules
file is found and only issues a warning when it doesn't have a section for this submodule. This is because the user might just use plain gitlinks without the.gitmodules
file or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him thatmv
would have done that for him).
Only when.gitmodules
is found and contains merge conflicts themv
command will fail and tell the user to resolve the conflict before trying again.
git 2.9 (June 2016) will improve git mv
for submodule:
See commit a127331 (19 Apr 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 9cb50a3, 29 Apr 2016)
mv
: allow moving nested submodules
"
git mv old new
" did not adjust the path for a submodule that lives as a subdirectory insideold/
directory correctly.
submodules however need to update their link to the git directory as
well as updates to the.gitmodules
file.
edited May 7 '16 at 7:43
answered Sep 10 '13 at 7:17
VonCVonC
848k29626973254
848k29626973254
Note to self: Try this on 1.8.4 and you will havefatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.
– checksum
Nov 29 '13 at 2:22
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
2
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
5
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
|
show 22 more comments
Note to self: Try this on 1.8.4 and you will havefatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.
– checksum
Nov 29 '13 at 2:22
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
2
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
5
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
Note to self: Try this on 1.8.4 and you will have
fatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.– checksum
Nov 29 '13 at 2:22
Note to self: Try this on 1.8.4 and you will have
fatal: source directory is empty, source=my_source, destination=my_destination
. Will try this again when 1.8.5 has stable release.– checksum
Nov 29 '13 at 2:22
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
@checksum But 1.8.5 has a stable release, for at least some... hours ;) github.com/git/git/releases/tag/v1.8.5
– VonC
Nov 29 '13 at 6:16
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
I had to build Git version 1.8.5.GIT from the source code because there is Git v.1.7.5 in Ubuntu repositories. How to build Git from the source code
– Maksim Dmitriev
Jan 17 '14 at 20:24
2
2
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
@MaksimDmitriev but what about a ppa (Personal Package Archive) that I mentioned in stackoverflow.com/a/20918469/6309?
– VonC
Jan 17 '14 at 20:32
5
5
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
This should be the "accepted" solution today. :/
– Jesse Adelman
Oct 12 '17 at 20:01
|
show 22 more comments
$ mv submodule-oldpath submodule-newpath
$ git rm submodule-oldpath
$ git add submodule-newpath
$ git submodule sync
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule.
the correct solution is:
$ mv submodule-oldpath ~/another-location
$ git rm submodule-oldpath
$ git submodule add submodule-repository-URL submodule-newpath
Source: http://bcachet.github.io/development/2012/05/25/rename-git-submodule/
2
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
add a comment |
$ mv submodule-oldpath submodule-newpath
$ git rm submodule-oldpath
$ git add submodule-newpath
$ git submodule sync
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule.
the correct solution is:
$ mv submodule-oldpath ~/another-location
$ git rm submodule-oldpath
$ git submodule add submodule-repository-URL submodule-newpath
Source: http://bcachet.github.io/development/2012/05/25/rename-git-submodule/
2
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
add a comment |
$ mv submodule-oldpath submodule-newpath
$ git rm submodule-oldpath
$ git add submodule-newpath
$ git submodule sync
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule.
the correct solution is:
$ mv submodule-oldpath ~/another-location
$ git rm submodule-oldpath
$ git submodule add submodule-repository-URL submodule-newpath
Source: http://bcachet.github.io/development/2012/05/25/rename-git-submodule/
$ mv submodule-oldpath submodule-newpath
$ git rm submodule-oldpath
$ git add submodule-newpath
$ git submodule sync
This solutions doesn’t work for me because when using git add command, the submodule was included into the project as a simple directory and not as a submodule.
the correct solution is:
$ mv submodule-oldpath ~/another-location
$ git rm submodule-oldpath
$ git submodule add submodule-repository-URL submodule-newpath
Source: http://bcachet.github.io/development/2012/05/25/rename-git-submodule/
edited May 6 '13 at 16:24
answered May 6 '13 at 15:09
Mahmoud AdamMahmoud Adam
4,02223248
4,02223248
2
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
add a comment |
2
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
2
2
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
Did you pull this word for word from this location? bcachet.github.io/development/2012/05/25/rename-git-submodule If so, please make sure to give attribution to that site in your answer.
– George Stocker♦
May 6 '13 at 16:17
add a comment |
I just tried a few of the suggested above. I'm running:
$ git --version
git version 1.8.4
I found it was best to de-init the submodule, remove the directory and create a new submodule.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
At least that is what worked for me best. YMMV!
add a comment |
I just tried a few of the suggested above. I'm running:
$ git --version
git version 1.8.4
I found it was best to de-init the submodule, remove the directory and create a new submodule.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
At least that is what worked for me best. YMMV!
add a comment |
I just tried a few of the suggested above. I'm running:
$ git --version
git version 1.8.4
I found it was best to de-init the submodule, remove the directory and create a new submodule.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
At least that is what worked for me best. YMMV!
I just tried a few of the suggested above. I'm running:
$ git --version
git version 1.8.4
I found it was best to de-init the submodule, remove the directory and create a new submodule.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
At least that is what worked for me best. YMMV!
answered Mar 10 '14 at 19:14
jaredwolffjaredwolff
492410
492410
add a comment |
add a comment |
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a git submodule sync
afterwards, but I'm not in a position to check right now.
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
1
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
add a comment |
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a git submodule sync
afterwards, but I'm not in a position to check right now.
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
1
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
add a comment |
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a git submodule sync
afterwards, but I'm not in a position to check right now.
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a git submodule sync
afterwards, but I'm not in a position to check right now.
answered Dec 24 '10 at 14:59
AbizernAbizern
102k30183238
102k30183238
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
1
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
add a comment |
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
1
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
This causes the new submodule name to occur as a new commit and not as a rename. But perhaps this is the way it has to be ?
– Lars Tackmann
Dec 24 '10 at 15:04
1
1
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
@Lars: Do be sure to remove the old submodule directory too!
– Cascabel
Apr 4 '11 at 14:53
add a comment |
It's not possible to rename it, so you've to remove it first (deinit
) and add it again.
So after removing it:
git submodule deinit <path>
git rm --cached <path>
you may also double check and remove the references to it in:
.gitmodules
.git/config
- remove reference folder from
.git/modules/<name>
(best to make a backup), as each folder hasconfig
file where it keeps the reference to itsworktree
then stage your changes by committing any changes to your repo by:
git commit -am 'Removing submodule.'
and double check if you don't have any outstanding issues by:
git submodule update
git submodule sync
git submodule status
so now you can add the git submodule again:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
also it is actually today
– Alexey
Oct 12 '18 at 12:53
add a comment |
It's not possible to rename it, so you've to remove it first (deinit
) and add it again.
So after removing it:
git submodule deinit <path>
git rm --cached <path>
you may also double check and remove the references to it in:
.gitmodules
.git/config
- remove reference folder from
.git/modules/<name>
(best to make a backup), as each folder hasconfig
file where it keeps the reference to itsworktree
then stage your changes by committing any changes to your repo by:
git commit -am 'Removing submodule.'
and double check if you don't have any outstanding issues by:
git submodule update
git submodule sync
git submodule status
so now you can add the git submodule again:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
also it is actually today
– Alexey
Oct 12 '18 at 12:53
add a comment |
It's not possible to rename it, so you've to remove it first (deinit
) and add it again.
So after removing it:
git submodule deinit <path>
git rm --cached <path>
you may also double check and remove the references to it in:
.gitmodules
.git/config
- remove reference folder from
.git/modules/<name>
(best to make a backup), as each folder hasconfig
file where it keeps the reference to itsworktree
then stage your changes by committing any changes to your repo by:
git commit -am 'Removing submodule.'
and double check if you don't have any outstanding issues by:
git submodule update
git submodule sync
git submodule status
so now you can add the git submodule again:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
It's not possible to rename it, so you've to remove it first (deinit
) and add it again.
So after removing it:
git submodule deinit <path>
git rm --cached <path>
you may also double check and remove the references to it in:
.gitmodules
.git/config
- remove reference folder from
.git/modules/<name>
(best to make a backup), as each folder hasconfig
file where it keeps the reference to itsworktree
then stage your changes by committing any changes to your repo by:
git commit -am 'Removing submodule.'
and double check if you don't have any outstanding issues by:
git submodule update
git submodule sync
git submodule status
so now you can add the git submodule again:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
answered Feb 28 '16 at 17:02
kenorbkenorb
69.7k29407414
69.7k29407414
also it is actually today
– Alexey
Oct 12 '18 at 12:53
add a comment |
also it is actually today
– Alexey
Oct 12 '18 at 12:53
also it is actually today
– Alexey
Oct 12 '18 at 12:53
also it is actually today
– Alexey
Oct 12 '18 at 12:53
add a comment |
MacOs: When I wanna use VonC solution to change submodule folder Common
to lowercase:
git mv Common common
I get
fatal: renaming 'Common' failed: Invalid argument
Solution - use some temporary folder name and move twice:
git mv Common commontemp
git mv commontemp common
That's all :)
add a comment |
MacOs: When I wanna use VonC solution to change submodule folder Common
to lowercase:
git mv Common common
I get
fatal: renaming 'Common' failed: Invalid argument
Solution - use some temporary folder name and move twice:
git mv Common commontemp
git mv commontemp common
That's all :)
add a comment |
MacOs: When I wanna use VonC solution to change submodule folder Common
to lowercase:
git mv Common common
I get
fatal: renaming 'Common' failed: Invalid argument
Solution - use some temporary folder name and move twice:
git mv Common commontemp
git mv commontemp common
That's all :)
MacOs: When I wanna use VonC solution to change submodule folder Common
to lowercase:
git mv Common common
I get
fatal: renaming 'Common' failed: Invalid argument
Solution - use some temporary folder name and move twice:
git mv Common commontemp
git mv commontemp common
That's all :)
answered Sep 5 '18 at 17:55
Kamil KiełczewskiKamil Kiełczewski
13.1k86896
13.1k86896
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4526910%2frename-a-git-submodule%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
You will no longer need to update
.gitmodules
manually when moving a submodule. see my answer below– VonC
Sep 10 '13 at 7:17
@VonC's answer worked like a charm for me
– laconbass
May 23 '15 at 3:31
Git modules are too complicated.
npm
shows how simple works. One day... maybe... someone... will rewrite it... in the meantime...– Rolf
Mar 18 '18 at 15:00
@VonC's answer is not the full story as of today: it will indeed change .gitmodules, but will just rename the path, not the module name. You need an additional edit to .gitmodules to correct that and a 'git submodule sync' to complete the full process
– zertyz
Dec 7 '18 at 22:06