How to clone a second branch using the same directory as the first cloned branch?

Asked

Viewed 343 times

3

I have a repository with several branches, cloned a specific one and worked on it.

Later the need to work on another branch of this same project arose, has how to clone it to the same folder of the first branch ?

  • Note: as the repository is very large, it is very time-consuming to clone the entire project at once.
  • How are you managing your remotes? You pushed something?

  • gitMerge? https://git-scm.com/book/pt-br/v1/Ramifica%C3%A7%C3%A3o-Branching-no-Git-B%C3%A1sico-de-Branch-e-merge

  • I’ve already pushed to the branch I cloned ... I don’t want to join branches, I just want to clone one more in the same folder

2 answers

0

You can use the command to work directly with the branch:

git checkout -b [branch] [nomeremoto]/[branch]

Or if you want to create another branch and merge.

Creating the branch:

git branch nomebranch

Giving a checkout:

git checkout nomebranch

Merging:

git merge nomebanchdesjado
  • when I try the first option happens the following "fatal: Cannot update paths and switch to branch 'test' at the same time. Did you intend to checkout 'origin/test' which can’t be resolved as commit? ", when running "git status" no modification appears

  • You have this test branch in the origin repository?

  • Yes, I have ......

  • But your origin repository is the local? or is the master?

  • is the remote ....

  • https://stackoverflow.com/questions/1783405/how-do-i-check-out-a-remote-git-branch tries to apply these steps.

Show 1 more comment

0

Yes.

  1. Starting point original branch -> develop

    >git status
    On branch develop
    Your branch is up to date with 'origin/develop'.
    
  2. Create first branch

    >git checkout -b feature/primeira-branch
    Switched to a new branch 'feature/primeira-branch'
    
  3. Now you are in the first branch modify something, add and Comite the changes. Example, I created a file helloworld.txt

    >notepad helloworld.txt
    
    >git status
    On branch feature/primeira-branch
    Untracked files:
    (use "git add <file>..." to include in what will be committed)
     helloworld.txt
    
    >git add .
    
    >git commit -m "Novo arquivo"
    [feature/primeira-branch a78c07d] Novo arquivo
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 helloworld.txt
    
  4. Now let’s go to a new branch continuing from the state we stopped at the first branch

    >git checkout -b feature/segundo-branch
    Switched to a new branch 'feature/segundo-branch'
    
  5. If you don’t want to start the second branch from where you first left off, go back to the develop or the branch you want to start and create your branch from there. For example, if I want to create a third branch starting from develop I should do so:

    >git checkout develop
    Switched to branch 'develop'
    Your branch is up to date with 'origin/develop'.
    
    >git checkout -b feature/terceiro-branch
    Switched to a new branch 'feature/terceiro-branch'
    
  6. By checking the change tree, I go to the branch of the second Feature to show the commit in front of the develop (git log prompt or gitk with graphical interface)

    >git checkout feature/segundo-branch
    Switched to branch 'feature/segundo-branch'
    
    >git log --oneline --graph
    * a78c07d (HEAD -> feature/segundo-branch, feature/primeira-branch) Novo arquivo
    * 69ccbd4 (origin/develop, origin/HEAD, feature/terceiro-branch, develop) 
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.