Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:00:31+00:00 2026-06-11T10:00:31+00:00

I recently started working on a project which uses Git for version control. I

  • 0

I recently started working on a project which uses Git for version control. I have to fix two defects, Defect1 and Defect2. Fixes for Defect1 and Defect2 need changes to File1 and File2 respectively. These two files are unrelated to each other.

I want to work on each defect in a separate Git branch. I created two branches, fix_Defect1 and fix_Defect2, and want to work on them independently. The fixes are complex, so I cannot complete one fix and commit it before switching to the other. I observe that when I switch from fix_Defect1 to fix_Defect2, any changes made to File1 also appear (and vice versa). Is there some way to avoid this from happening?

From the Git help, I could not figure out any way. I also searched on SO for git work with multiple branches, and found Git and working on multiple branches and Using git with multiple branches at once, which are close but somewhat different from my question.

I can clone multiple copies of the repository per branch in a separate directory, but it seems like I would be missing the full power of Git branching by doing so, besides wasting disk space. Could you please suggest a good approach to handle this scenario?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:00:32+00:00Added an answer on June 11, 2026 at 10:00 am

    Your problem arises from the fact that you’re changing files in the working directory (e.g. file1 and file2) but are not committing or stashing those changes. The best solution is to commit the changes when you feel like switching branches:

    git add file1 file2 ;# add whichever ones you've fixed
    git commit ;# commit the work in progress
    git checkout fix_Defect2 ;# now checkout the other branch
    

    Of course, kitchen sink commits, those that include work in progress and possibly broken code, aren’t particularly good for your history. You can always use git rebase to clean up your history later. See, for example, this answer for details or this answer for the philosophy behind it.

    Finally, if you don’t like the idea of committing your work, you can also use git stash to get something like the same result:

    git stash ;# when you're ready to switch
    git checkout fix_Defect2 ;# work on this branch for a while
    git commit -A ;# be sure to commit your work on 'fix_Defect2'
    git checkout fix_Defect1 ;# checkout the original branch
    git stash pop ;# reapply the work you stashed from the working directory
    

    I don’t recommend the stashing solution, generally. The stashing machinery isn’t terribly robust, and is more designed for situations where you need to hotfix something, not balance two equally complex feature branches.

    For more details, check out the “File Status Lifecycle” diagram in the git-scm docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started working on some open source project which I found relevant
I use git as my primary version control system, and have recently started using
Recently we started working with Database project in Visual Studio 2010. I have added
I have a project that I have recently started working on seriously but had
I've recently started working on a project that uses bazaar. I'm attempting to find
I recently started using Git as my version control system for some Cocoa projects
I have been working with a small project recently which involves Struts 2 and
I recently started working on a web project which was already in progress; the
I have recently started working on a very large C++ project that, after completing
I`m an Android developer, and recently started working on JAVA PC project for client.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.