1

Beginner GitHub user here, cannot figure out how to use it.

I have a repository, it has two branches, one is called main, and it has a README file, and there is another called master, with all my other files. Only a few files.

I pushed them from my desktop, and when I want to clone or pull the entire repository to my laptop, it only pulls the README file, nothing else; so basically the content of the branch called main.

Any help will be greatly appreciated, thanks in advance.

Akos
  • 43
  • 1
  • 5
  • 2
    Does this answer your question? [Git pull a certain branch from GitHub](https://stackoverflow.com/questions/1709177/git-pull-a-certain-branch-from-github) – Software2 Jul 23 '21 at 23:20
  • `git clone` will generate a local copy of the repo. Use `git checkout master` to switch to the branch with all the other files. – Christian Jul 23 '21 at 23:26

2 Answers2

6

When you clone a remote repository, by default your local working directory will be on the remote repository's default branch. For a long time this was the master branch, but GitHub has recently started using the name main instead of master.

It sounds like your repository may have been created someplace else and then pushed to GitHub. Regardless of how you arrived at this situation, you have two branches named main and master, and it sounds like main is the default branch.

After cloning the repository, you will be on the main branch. You can switch to the master branch by running:

git switch master

Or:

git checkout master

The git switch syntax is newer. The two commands are largely equivalent (git checkout does more than git switch).


You can change the default branch of your GitHub repository by going to your repository settings. Clicking on "Branches" along the left. This will take you to the branch settings, where the first section is the "Default branch" section.

Click on the icon with two arrows, then select master as your default branch.

In the future, git clone will result in a working directory that is on the master branch.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
larsks
  • 277,717
  • 41
  • 399
  • 399
2

If you only see the README.md file, then you stay in the main branch. Every repository have a default branch. In your case is this the main branch. And this default branch is checked out automatically after git clone.

git branch -a lists all existing branches and also in which branch you currently stay. If you execute git checkout master (command for changing branches) you would be able to see also the other few files, because you are then in the other branch.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34