LinuxCommandLibrary

git-touch

Create empty files and update timestamps

TLDR

Create new files and add them to the index

$ git touch [path/to/file1 path/to/file2 ...]
copy

SYNOPSIS

git touch [-a] [-m] [-c] [--no-create] [--add] [--no-add] file...

PARAMETERS

-a
    Change only access time

-m
    Change only modification time

-c, --no-create
    Do not create nonexistent files

--add
    Stage files with git add after touch

--no-add
    Explicitly skip staging (default)

DESCRIPTION

git-touch is not a built-in core Git command but a popular user-defined alias, script, or extension (e.g., in git-extras or custom configs) that emulates the Unix touch command within Git repositories. It updates file access and/or modification timestamps, creates empty files if they don't exist, and can automatically stage changes via git add for immediate version control integration.

This streamlines workflows: instead of running touch file.txt && git add file.txt, a single git touch file.txt --add suffices. It detects the current Git repo using git rev-parse and fails gracefully outside one. Useful for creating placeholder files, refreshing build timestamps before commits, or marking files as 'touched' in scripts.

Implementations vary: some mirror touch(1) exactly then add, others use git update-index for index-only updates without filesystem changes. Check git config --get-regexp alias.touch or installed extensions. Widely adopted in dotfiles, Oh My Zsh plugins, and dev environments since the early 2010s for productivity.

Limitations include no support for advanced timestamp specs (use touch -t manually) and potential conflicts with ignored files.

CAVEATS

Not standard Git; availability depends on aliases/extensions. Ignores .gitignore by default. Use in repo only; varies by implementation.

COMMON ALIAS

git config --global alias.touch '!f() { touch "$@" && git add "$@"; }; f'
Sets global alias to touch + add.

EXAMPLE USAGE

git touch src/*.py --add
Updates Python files and stages them.
git touch README.md -c
Refreshes timestamp without staging.

HISTORY

Emerged as Git aliases ~2010-2015 in communities like GitHub dotfiles and bash-it. Included in git-extras (2013+) and zsh plugins for workflow efficiency.

SEE ALSO

Copied to clipboard