Cheat sheets for various stuff
Action | Command |
---|---|
Create a tag (annotated) | git tag -a -m 'MESSAGE' TAGNAME [COMMIT] |
List tags (and NUM lines of annotation) | git tag -l -nNUM |
Delete tag | git tag -d TAGNAME |
Source: http://davidwalsh.name/git-remove-submodule
Delete section from .gitmodules
: 3 lines, starting with
[submodule "MODULE"]
.gitmodules
: git add .gitmodules
Delete section from .git/config
: 2 lines, starting with
[submodule "MODULE"]
git rm --cached path/to/submodule
rm -rf .git/modules/MODULE
git commit -m 'Removed module MODULE'
rm -rf path/to/submodule
(removes now untracked submodule files)You have a project app
where one of the modules, widget
, would better be kept in a separate Git repository. We’ll assume widget
now resides in a directory immediately under the project root ~/projects/app/widget/
. The app
project is on Github, at git@github.com:user/app.git
.
The goal is to have widget as a separate project ~/projects/widget/
, with its own Github repository git@github.com:user/widget.git
. We’ll assume this repository has been created and is still empty.
Go to project root:
$ cd ~/projects/app/
Create a branch that contains only commits for files in widget
:
$ git subtree split --prefix=widget/ --branch=subtree/widget
Push this new branch to its own repository:
$ git push git@github.com:user/widget.git subtree/widget:master
Create widget
project directory:
$ mkdir ~/projects/widget/; cd ~/projects/widget/
Pull the widget
project from Github into its own directory:
$ git clone git@github.com:user/widget.git
Maybe do some more development, and release the first version:
$ git tag -a -m 'First stable release' v1.0.0
$ git push --tags
At this time, you have two separate repositories. However, app/widget/
is still part of the original repository. However, now it should be maintained in its own repository, and changes should be pulled into app
from widget
:
Remove the widget
directory from the app project
:
$ cd ~/projects/app/
$ git rm -rf widget/
$ rm -rf widget/ # delete ignored files that were left behind
Fetch the widget
release from Github (--squash
“summarizes” all changes as single commit):
$ git subtree add --prefix=widget/ --squash github.com:user/widget.git tags/v1.0.0