There is a project on which I work mostly at work.

There are a few commits I have made to the server. Now I want to transfer the branch to my home machine, it would be nice to know how to make a partial transfer.

I do the following:

$ git checkout -borigin/fragments $ git checkout -b fragments origin/fragments 

In the terminal I see the following:

 > M AndroidStudioProjects/TestTask/app/build.gradle M AndroidStudioProjects/TestTask/app/src/main/java/com/simpals/testtask/ac M AndroidStudioProjects/TestTask/app/src/retrofit/java/com.simpals.testtas Switched to a new branch 'fragments' 

But I do not see any files added.

    2 answers 2

    You should start with the fact that you have unsaved changes on your home machine. Three lines starting with M are files that have been m odified since the last commit. Save these changes to any branch, but not to master . Suddenly they are valuable.

    It seems that you have once cloned this project on a home machine. But you started your branch from the working machine to the server later, so there are no corresponding commits in the repository on the home machine. The git repositories do not support any permanent connection, similar to the IMAP mail protocol. To update the data, you must explicitly execute the command:

     git fetch origin 

    Now you will have (or update if you already had) the origin/fragments tracking branch. You can easily create a corresponding local branch, but only if the name is not yet taken:

     git checkout fragments 

    In this case: 1. A local branch is created with the name fragments 1. This branch is configured to push and pull into the fragments branch of the origin repository, which is represented by the origin/fragments branch

    If you have already created the corresponding branch and the name is taken (this is so, judging by the commands given in the question), you just need to rearrange it to a new commit:

     git checkout fragments git reset origin/fragments 

    And to link it with the origin/fragments branch, when you push the changes, do this:

     git push -u origin fragments 

      so try git clone http://repozitoriy.git -b branch-name

      • Fatal: Remote branch - not found in upstream origin - Morozov
      • I can’t clone a branch into a project - Morozov
      • you clone into a folder then you need to do merge. - Version8
      • updated question, please take a look - Morozov
      • @ Version8 why then do merge? - Nick Volynkin