Skip to content
5 changes: 5 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

- [`git abort`](#git-abort)
- [`git adopt`](#git-adopt)
- [`git alias`](#git-alias)
- [`git archive-file`](#git-archive-file)
- [`git authors`](#git-authors)
Expand Down Expand Up @@ -1632,6 +1633,10 @@ Note above, that because of the `--newer` flag, the file `git-alias` was not tou

Abort current revert, rebase, merge or cherry-pick, without the need to find exact command in history.

## git adopt

Move each file into repo and symlink it back in place. Handy for dotfiles.

## git magic

Commits changes with a generated message.
Expand Down
83 changes: 83 additions & 0 deletions bin/git-adopt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash
#
# (The MIT License)
#
# Copyright (c) 2025 Neal Fultz <nfultz@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# 'Software'), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# The below is a small script for dotfile management.

adopt () {

if [ "$1" == "-d" ]; then
local DEBUG
DEBUG=echo
shift
fi

local package
package="$1"
shift

local has_git
local repo
local target

if hash git 2>/dev/null ; then
has_git=1
repo=$(git config --path --default "$HOME/.dotfiles" adopt.repo)
target=$(git config --path --default "$HOME" adopt.target)
else
has_git=0
repo=${repo:-$HOME/.dotfiles}
target=${target:-$HOME}
fi




package="$package${PWD#*$target}"
$DEBUG mkdir -p "$repo/$package"

for i in "$@"
do
dn=$(dirname $i)
[ -n "$dn" ] && $DEBUG mkdir -p $repo/$package/$dn
$DEBUG mv $i $repo/$package/$dn
$DEBUG ln -rs $repo/$package/$i $i
if [ $has_git -gt 0 ]; then
$DEBUG git -C $repo add -f $package/$i
fi
done


if [ $has_git -gt 0 ]; then
$DEBUG git -C $repo commit -e -m "adopt: ${package%%/*}"
fi
}

[ $# -ge 2 ] && adopt "$@" || cat <<EOF
Usage: git adopt [-d] pkg file...

Move each file into repo and symlink it back in place.

EOF

1 change: 1 addition & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ zstyle -g existing_user_commands ':completion:*:*:git:*' user-commands
zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
alias:'define, search and show aliases' \
abort:'abort current revert, merge, rebase, or cherry-pick process' \
adopt:'move files into repo and symlink back' \
archive-file:'export the current head of the git repository to an archive' \
authors:'generate authors report' \
browse:'open repo website in browser' \
Expand Down
58 changes: 58 additions & 0 deletions man/git-adopt.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.\" generated with Ronn-NG/v0.10.1
.\" http://github.com/apjanke/ronn-ng/tree/0.10.1
.TH "GIT\-ADOPT" "1" "June 2025" "" "Git Extras"
.SH "NAME"
\fBgit\-adopt\fR \- Move each file into repo and symlink it back in place
.SH "SYNOPSIS"
\fBgit adopt\fR [\-d] <pkg> <files>\|\.\|\.\|\.
.SH "DESCRIPTION"
For each file specified:
.IP "1." 4
Move it to the pkg folder inside a repo
.IP "2." 4
Create a symlink pointing to that
.IP "3." 4
Commit the new files\.
.IP "" 0
.P
Any necessary subfolders will also be created automatically\.
.SH "OPTIONS"
\-d
.P
Dry run \- output shell commands instead of executing\.
.SH "EXAMPLES"
.nf
# Minimal setup
git init \-b `whoami`@`hostname` \.dotfiles
git adopt \-d bash \.bashrc
git adopt bash \.bashrc
.fi
.SH "GIT CONFIGS"
You can customize the adoption repo and target directories via git config options
.IP "" 4
.nf
$ git config \-\-global add adopt\.repo <repo>
.fi
.IP "" 0
.P
The default repo path is \fB$HOME/\.dotfiles\fR\.
.IP "" 4
.nf
$ git config \-\-global add adopt\.target <target>
.fi
.IP "" 0
.P
The default target is \fB$HOME\fR\.
.P
Of course, the user's git config is itself a file that can be tracked via \fBgit\-adopt\fR:
.IP "" 4
.nf
$ git adopt git \.config/git/config
.fi
.IP "" 0
.SH "AUTHOR"
Written by Neal Fultz \fInfultz@gmail\.com\fR\.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR> <\fIhttps://dotfiles\.github\.io/\fR> stow(8)
150 changes: 150 additions & 0 deletions man/git-adopt.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions man/git-adopt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
git-adopt(1) -- Move each file into repo and symlink it back in place
================================

## SYNOPSIS

`git adopt` [-d] &lt;pkg&gt; &lt;files&gt;...

## DESCRIPTION

For each file specified:

1. Move it to the pkg folder inside a repo
2. Create a symlink pointing to that
3. Commit the new files.

Any necessary subfolders will also be created automatically.

## OPTIONS

-d

Dry run - output shell commands instead of executing.

## EXAMPLES

```
# Minimal setup
git init -b `whoami`@`hostname` .dotfiles
git adopt -d bash .bashrc
git adopt bash .bashrc
```

## GIT CONFIGS

You can customize the adoption repo and target directories via git config options

$ git config --global add adopt.repo <repo>

The default repo path is `$HOME/.dotfiles`.

$ git config --global add adopt.target <target>

The default target is `$HOME`.

Of course, the user's git config is itself a file that can be tracked via `git-adopt`:

$ git adopt git .config/git/config

## AUTHOR

Written by Neal Fultz <nfultz@gmail.com>.

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
&lt;<https://dotfiles.github.io/>&gt;
stow(8)
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# manuals
git-abort(1) git-abort
git-adopt(1) git-adopt
git-alias(1) git-alias
git-archive-file(1) git-archive-file
git-authors(1) git-authors
Expand Down
Loading
Loading