Skip to content

Instantly share code, notes, and snippets.

@MarWeUMR
Last active October 15, 2023 14:31
Show Gist options
  • Save MarWeUMR/ccf5b97ffccc1d72e0d8c5bd368be1c5 to your computer and use it in GitHub Desktop.
Save MarWeUMR/ccf5b97ffccc1d72e0d8c5bd368be1c5 to your computer and use it in GitHub Desktop.
Git Stuff

How to initialize a bare git repo with nice worktree structure

my-awesome-project
 - git-technical-directory
 - new-feature
 - hotfix

Start with a directory and clone your remote:

git clone --bare [email protected]:myname:my-awesome-project.git .bare
echo "gitdir: ./.bare" > .git

Next up, you can add branches as worktrees with:

git worktree add new-feature
git worktree add hotfix master

The directory should look something like this now:

my-awesome-project
 - .bare
 - .git
 - new-feature
 - hotfix

Source

https://morgan.cugerone.com/blog/how-to-use-git-worktree-and-in-a-clean-way/

How to ignore file changes in a file, without using gitignore?

This is, for instance, usefull when having a file tracked by git with secret contents. You can have the file in your repository with defaults and then change your local data. --skip-worktree will help to keep git status silent without the need to actually ignore the file.

Skip file changes:

git update-index --skip-worktree <file_name>

Undo Operation:

git update-index --no-skip-worktree <file_name>

Source

https://compiledsuccessfully.dev/git-skip-worktree/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment