How do I create a master branch in a bare Git repository?

后端 未结 4 826
夕颜
夕颜 2020-12-13 00:13

(All done in poshgit on Windows 8):

git init --bare test-repo.git
cd test-repo.git

(Folder is created with git-ish files and folders inside

4条回答
  •  萌比男神i
    2020-12-13 00:20

    A bare repository is pretty much something you only push to and fetch from. You cannot do much directly "in it": you cannot check stuff out, create references (branches, tags), run git status, etc.

    If you want to create a new branch in a bare Git repository, you can push a branch from a clone to your bare repo:

    # initialize your bare repo
    $ git init --bare test-repo.git
    
    # clone it and cd to the clone's root directory
    $ git clone test-repo.git/ test-clone
    Cloning into 'test-clone'...
    warning: You appear to have cloned an empty repository.
    done.
    $ cd test-clone
    
    # make an initial commit in the clone
    $ touch README.md
    $ git add . 
    $ git commit -m "add README"
    [master (root-commit) 65aab0e] add README
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 README.md
    
    # push to origin (i.e. your bare repo)
    $ git push origin master
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To /Users/jubobs/test-repo.git/
     * [new branch]      master -> master
    

提交回复
热议问题