A little lost setting up my git starting state – I'm sure it's just a couple simple commands, but


  • User “dev”, home directory /home/dev
  • Production code in what I’ll call /thepath/codebase
  • Working directory /thepath/dev (currently with files that should be a branch)
  • Project is called KizunaDB

Ultimately I want a bare repo called kizunadb.git somewhere (I guess my home directory is logical) that I want seen as the “original”, where everything clones from. (per conclusions from this discussion)

  • IntelliJ IDEA - What is the keyboard shortcut for 'git pull' command?
  • Add git hook to repo
  • Moving a git repository down a hierarchy level
  • How does Git track history during a refactoring?
  • Allowing all users to create a repo in TFS-GIT
  • Git workflow on Heroku
  • Not knowing how to start with an empty bare repo and then put files into it from elsewhere, I tried starting where the files are. I successfully made a repo in /thepath/codebase and committed all the files. Then I did:

    cd ~
    mkdir kizunadb.git
    cd kizunadb.git
    git clone --bare /thepath/codebase

    Hmm… that made /home/dev/kizunadb.git/codebase.git – not quite what I had in mind.

    1. I can do it again from /home/dev/ to fix the location, but it will still be called codebase.git – if I just change the name, will I break it?
    2. And then how do I swap roles between it and the codebase directory so that later I can get completed code from kizunadb.git to /thepath/codebase (with clone or checkout – not sure which is the right command at that point)? I know git doesn’t really have the concept of “the main one”, but I have noticed references in tutorials to “original” – not sure how that plays in…
    3. And then, how do I clone the repo to /thepath/dev so I can do branches without losing my work in progress? (I know I could move the whole directory out of the way, clone the repo, and then overwrite the repo’s files, but I suspect there is an easier way.)

    I’m happy to just start over if I have done things in the wrong order.

  • Completely remove commit from git database
  • How to quickly mark resolution having conflicts during rebase?
  • git merge conflict due to moved files
  • Git, how to commit only a specific directory?
  • git show HEAD - How to skip on large files such as Illustrator files while reviewing files
  • Issues while creating repository?
  • One Solution collect form web for “A little lost setting up my git starting state – I'm sure it's just a couple simple commands, but”

    First, this would work better:

    cd ~
    git clone --bare /thepath/codebase kizunadb.git

    Second, a bare repo is for contributor to push to.

    But to initialize your bare repo properly with codebase content, I would rather follow the workflow describe in ““fetch --all” in a git bare repository doesn’t synchronize local branches to the remote ones”:

    cd /thepath/codebase
    git clone --mirror . ~/kizunadb.git
    git push ~/kizunadb.git --mirror 

    It can be completed with a post-receive hook in order to cd to the second non-bare repo and pull from the bare repo: see more at “Is –bare option equal to core.bare config in Git?”.
    That supposes /thepath/codebase is a git repo.

    /thepath/dev would be a simple clone of the bare repo kizunadb.git, for you to develop in.

    git stash will allow you to make branch without losing your work in progress.
    See “GIT: commit changes to old/safe branch while in new/dirty/dev branch without checking out or losing unstaged data”.

    As you mention in the comments, for a single developer, a bare repo might be superfluous.
    You could:

    • have only one repo: /thepath/dev
    • use a “git --git-dir=/thepath/dev/.git --work-tree=/thepath/codebase checkout -f” whenever you want to deploy code.

    In that case, /thepath/codebase wouldn’t even be a git repo, but simply a tree considered as a working directory for /thepath/dev on deployment.

    Git Baby is a git and github fan, let's start git clone.