DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • The SPACE Framework for Developer Productivity
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Observability Architecture: Financial Payments Introduction
  • RBAC With API Gateway and Open Policy Agent (OPA)

Trending

  • The SPACE Framework for Developer Productivity
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Observability Architecture: Financial Payments Introduction
  • RBAC With API Gateway and Open Policy Agent (OPA)
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. GitTip: Skip WorkTree

GitTip: Skip WorkTree

Use the skip-worktree command in git to modify a file in a local environment that git won't detect modification on to avoid affecting other files.

Oscar Galindo user avatar by
Oscar Galindo
·
Jan. 03, 20 · Tutorial
Like (13)
Save
Tweet
Share
29.94K Views

Join the DZone community and get the full member experience.

Join For Free

hopscotch board

Use skip-worktree to sneak in modifications git won't notice

GitTip: Skip WorkTree

This tip is simple and powerful in equal parts. What we want to achieve is to modify a local file that git could not identify as having been modified despite being already tracked. For this example, I have a file “config.txt” with the content: “secret.” This file works well in all environments, but in the local environment, I need to change it for testing. No problem: it is modified, the relevant tests are made, it is reverted and it is uploaded.

The problem comes when that file, for various reasons, has to be modified in your local environment and has to work without being uploaded to avoid affecting other files. How can we do that?

You may also enjoy: The 2016 Git Retrospective: Worktrees

My Apiumhub colleague (kudos to Álvaro Garcia) told me about the command git update-index –assume-unchanged, and I have to say that it did what I needed it to do. It allowed me to modify a file in a local environment and git did not detect it, so I could keep making changes in other files and committing files with my favorite git add without worrying about anything.

In the following image we can see how running git status shows us two files, config.txt and otrofichero.sh. As we said, we don’t want to upload config.txt, it is a change in a local environment and we don’t want to worry about it. After running the command  update-index  the file config.txt disappears from the working area.

Running update-index

The file still exists and git is not going to refresh it unless two things happen:

  • Manual deactivation of the bit with which we have marked that file (assume-unchanged)
  • Pulling and modifying that file via upstream

Before this last scenario in which we worry about the file, we have to review each pull to see whether the bit has been removed or not with the command  git ls-files -v :

git ls-files

Here we see that config.txt is marked with a lowercase “h” while otrofichero.sh has an “H” in uppercase. This letter represents the difference between a file cached by git and another that is not.

In short, this command does not work for our use case. Based on the documentation, this command marks large files as "not cached" and improves our performance with git. If what we wand is for git not to review a specific file, the option we are looking for is  –skip-worktree :

I’m not going to go in deep with that anymore, as this last option is similar to  assume-change , but it keeps the flag before the pulls.  Assume-change should be used for large files tracked by git like SDKs and so on while skip-worktree fits more with configuration changes for local environment tests so wedon't have to worry about uploading them to our remote repository.

Having said that, herevery useful git aliases related to the article. The name of the alias itself defines the action it does:

Shell




x
11
9


 
1
[alias]
2
   hide = update-index –skip-worktree
3
   unhide = update-index –no-skip-worktree
4
   unhide-all = ls-files -v | grep -i ^S | cut -c 3- | xargs git update-index
5
–no-skip-worktree
6
   hidden = ! git ls-files -v | grep ‘^S’ | cut -c3-



Further Reading

Tracking File Permissions in Git

Commands and Operations in Git
Git

Published at DZone with permission of Oscar Galindo. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • The SPACE Framework for Developer Productivity
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Observability Architecture: Financial Payments Introduction
  • RBAC With API Gateway and Open Policy Agent (OPA)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: