-3

I currently use git clone to get my files back in my local. My problem is when i run the command only the master files was download but the other branch was not download, so I'm thinking you guys could help me what should i do to get all the files in my repository including all the created files in a certain branch.

I'm new to git that's why i don't know the exact process to do this

I have look at this How to fetch all git branches but it does not help me..

Community
  • 1
  • 1
jameshwart lopez
  • 2,677
  • 5
  • 26
  • 56

2 Answers2

3

Let's say I have a repository with three branches

1 - master
2 - feature1
3 - feature2

You can then perform a git clone which will clone the entirety of the repo onto your local machine and will default you to the master branch; however, if you want to instead see the code on one of the feature branches, you will need to "checkout" that code on your local machine. You have at least three ways of things panning out here:

git checkout master

Git will tell you that you are already on the master branch

git checkout nonExistantBranch

Git will tell you that the requested branch does not exist

git checkout feature1

Git will successfully "checkout" the code. So, when you open any of the files on your local machine, they will reflect the code found on that specific branch only. This is the option that you want.

If you are getting an error saying the branch doesn't exist, but you think it does, perform a git branch -v which will show all the branches in the current repository.

There is a another option

git checkout -b newBranch 

This will tell git to switch to "newBranch" and if it doesn't exist, create it, using the code that is currently found on the branch you currently have checked out.

JDrost1818
  • 964
  • 5
  • 21
  • sir if i run that checkout it will create another branch right? – jameshwart lopez Jul 06 '15 at 02:21
  • It will not. It will switch to it if it exists. If it doesn't exist, it will say something like "branch not found". – JDrost1818 Jul 06 '15 at 02:22
  • sir could you update your answer starting from git clone down to getting the files in other branch? because when i run the checkout command error came up. It would be a great answer. :) – jameshwart lopez Jul 06 '15 at 02:24
  • @jameshwartlopez when you run `git clone` it gets the entire repo (including branches). A link to the documentation: http://git-scm.com/docs/git-clone – disinfor Jul 06 '15 at 02:44
0

You did download the content of all branches, but git checked-out only the master branch. To see other branches, run git branch --all (or git branch -a for short). A branch named foo on the remote repository will be tracked as remotes/origin/foo in your repository. At the time of cloning, your remotes/origin/foo will be exactly identical to the remote's foo. If the remote foo gets updated later, you can update your remote-tracking with git fetch.

As the other answer noted, you can checkout remotes/origin/foo with git checkout foo, which is a shortcut for git checkout -b foo --track remotes/origin/foo.

Matthieu Moy
  • 11,096
  • 2
  • 35
  • 57