10

My colleague created a repository in Bitbucket. I first created a folder in my computer and typed git init. After which,I made a clone from the repository to my computer using the command: git clone address.

But when i type git branch, there is no reply. It doesn't indicate which branch am i in.

git init
Initialized empty Git repository in /Users/IMAC/GsAdmin/.git/
git clone address
Cloning into 'gsadmin'...
Password: 
remote: Counting objects: 32, done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 32 (delta 3), reused 0 (delta 0)
git branch
git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .DS_Store
#   gsadmin/
nothing added to commit but untracked files present (use "git add" to track)

What is my mistake? Need some guidance.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
lakshmen
  • 28,346
  • 66
  • 178
  • 276

2 Answers2

26

There are two ways to create a git repository. You can use git init to create a new one, or you can use git clone to clone an existing one. If you run both init and clone then git will first create a new empty repository in the current directory and then clone the remote repository into a subdirectory of the empty one.

If you run git branch in the current directory then it will return no branches as the repository is empty and the master branch will be created with the first commit. If you go into the subdirectory then git branch should list the one branch that was created from the remote repository's default branch.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
1

The Problem

You've essentially created an untracked submodule in your top-level directory. From your description, you initialized an empty directory, and then cloned your BitBucket repository into a subdirectory of your newly-initialized repository.

The Solution

From your current directory, change directories into your current clone.

cd gsadmin
git status

You can move the gsadmin directory around, or re-clone it somewhere else. Either way, the solution is not to clone inside an existing git directory unless you're using submodules.

See Also

Why is "git branch" silent in new repositories?

Community
  • 1
  • 1
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199