A little lost setting up my git starting state – I'm sure it's just a couple simple commands, but
- User “dev”, home directory
- Production code in what I’ll call
- 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)
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.
- 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?
- And then how do I swap roles between it and the codebase directory so that later I can get completed code from
/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…
- And then, how do I clone the repo to
/thepath/devso 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.
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?”.
/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.
- have only one repo:
- 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.