Switch to en
1

Occasionally Useful Git Commands You Just Have to Know as a Dev

Occasionally Useful  Git Commands You Just Have  to Know as a  Dev

๐Ÿงฐ Useful Git commands

๐Ÿ”— Init & Update Submodules

Useful for complex projects using submodules.

git submodule update --init --recursive
  • Clones all configured submodules.
  • Checks them out to the commit stored in the parent repository.

โœ… Additional Submodule Commands

# Add a submodule
git submodule add <repository-url> [<path>]

# Pull new commits in submodules
git submodule update --remote

# Remove a submodule (manual cleanup required)
git submodule deinit -f <path>
rm -rf .git/modules/<path>
git rm -f <path>

๐Ÿ‘ค Change the Author of Every Commit

When you've used the wrong Git user/email across all commits.

git rebase -r --root --exec "git commit --amend --no-edit --reset-author"
  • Rewrites entire history and sets author to current Git config.
  • Make sure you've updated your author beforehand:
git config user.name "Your Name"
git config user.email "you@example.com"

๐Ÿ’ก Consider using conditional Git config for personal vs. work projects.


๐Ÿชข Enable Symlinks on Windows

When symlinks appear as plaintext files, enable this config:

git config --local core.symlinks true
git reset --hard HEAD
  • Re-enables symlink behavior locally.
  • โš ๏ธ Warning: git reset --hard will delete untracked files. Make sure the working directory is clean.

๐Ÿ”„ Reset & Clean Working Directory

git reset --hard
git clean -fd
  • Discards all changes (tracked + untracked).
  • Use when you want a truly clean slate.

๐Ÿ” Search Commit History

git log -S'search-term'
  • Shows commits that added/removed the specified string.
git log -G'regex-pattern'
  • Shows commits that match the regex pattern in diffs.

๐Ÿงช Dry Run Push or Clean

git push --dry-run
git clean -fdn
  • Shows what would happen without actually performing the command.

๐Ÿงญ Bisect to Find a Bug

Use binary search on commit history to find where a bug was introduced.

๐Ÿ”น Basic Workflow

git bisect start
git bisect bad                # current commit has the bug
git bisect good <commit>     # known good commit (e.g., a tag or old hash)

# Git now checks out commits in-between. Test and mark each as:
git bisect good
# or
git bisect bad

# When finished
git bisect reset
  • Efficiently narrows down the first bad commit.
  • Useful when you don't know which commit introduced the bug.
  • Useful when you have a large number of commits between releases.

๐Ÿ’ก You can automate the process with a script:

git bisect run ./test-script.sh

Occasionally Useful Git Commands You Just Have to Know as a Dev | Moritz Roessler | Senior Frontend Developer