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 6926109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:52:31+00:00 2026-05-27T10:52:31+00:00

This is a follow-up on this question on creating branches. It strikes me as

  • 0

This is a follow-up on this question on creating branches.

It strikes me as odd that I would still work on one repository because the files on my local machine will be a weird mix of different experiments.

I would imagine the best-practice method is to duplicate the repository and work in different folders on my computer for each branch — but I don’t know how to set this up. I have my current repository at Documents/San/CompProj so what are the commands I’d use to create a new repository tied to a different branch on a different local folder?

Git is fairly new to me so I’d love any corrections you can make on what I’m assuming/asking above.

  • 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-05-27T10:52:32+00:00Added an answer on May 27, 2026 at 10:52 am

    As of Git 2.5, git-worktree directly supports this workflow. See VonC’s answer to this question for details.

    My answer below may suffice if you don’t like git-worktree for whatever reason.


    Git is designed to allow you to work within a single folder on disk. This is a single repository that contains all the branches you care about.† You checkout whichever branch you want to work on at the time.

    Within a Git repository, you can only have a single branch checked out at a time. If you check out a second branch, the files on disk are removed and replaced with those from the second branch.

    If you have the following branches:

    BRANCH-A        BRANCH-B
    alpha.txt       alpha.txt
    bravo.txt
    charlie.txt     charlie.txt
                    delta.txt
    

    When you’re on branch-A and you checkout branch-B, then bravo.txt will be removed and delta.txt will be added to your working directory.

    However, git-checkout will not overwrite changes you’ve made to files unless you supply the -f argument. If you make a change to alpha.txt then try to switch to branch-B, you’ll get a message warning you that your changes would be lost and aborts the checkout.

    The exceptions are untracked files. If you have branch-A checked out and you create a new file called echo.txt, Git will not touch this file when you checkout branch-B. This way, you can decide that you want to commit echo.txt against branch-B without having to go through the hassle of (1) move the file outside the repo, (2) checkout the correct branch, and (3) move the file back into the repo.


    Footnote

    † Actually, Git doesn’t force you to use a single working directory. If you want, nothing is stopping you from creating different paths on disk for each branch you want to work on.

    /home/me/project
     +-- branch-a/
     +-- branch-b/
     +-- ...
    

    Each of these paths is its own Git repository (each one has a .git folder inside), and you can push and pull commits between the repos.

    cd ~/project                     ## Go to my projects directory
    git clone branch-a branch-b      ## Create a new branch-b
    
    cd branch-b
     ... work work work ...
    git commit -a -m "Made some changes on branch-b"
    
    git pull origin                  ## Fetch and merge the changes from branch-a
    git push origin                  ## Push my changes back to branch-a
    

    This is how some people use Mercurial if they aren’t using named branches: they clone the repository into a new directory on disk for each branch they want, then push and pull changesets between them.

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

Sidebar

Related Questions

This is a follow-up question to this one . Take a look at these
This is a follow-on question from the one I asked here . Can constraints
This is a follow-up to another question I asked earlier today. I am creating
This is a more specific question to follow up on [another question that I
This question is a follow up to my earlier question: Creating a valid XSD
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
This is a follow on question to How do I delete 1 file from
This is a follow-on question to the How do you use ssh in a
This is a follow up question to This Question . I like (and understand)
This is a follow up question . So, Java store's integers in two's-complements and

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.