1

I have <path1> in /f/gittest/foo (remote). I have <path2> in /f/gittest/bar (local).

Since I don't need remote to be a working copy right now, mostly because I can't push into an active branch, I made it bare.

I go through and create a .git directory and run git init --bare inside /f/gittest/foo/.git. I go in and add a remote repo to the local repository, make files, add, commit, and push to the remote. Changes appear to push and the remote is successfully up-to-date. However, the files tracked by the local repository (let's say example1.txt and example2.txt) aren't shown in the remote (though I suppose are tracked in the remote repo). How do I get this remote directory to be updated with the files that were pushed? I had previously succeeded with this without fetching and without mirroring, though I can't recall how.

Double-checked behavior: mkdir alpha/; mkdir beta/; cd beta/

mkdir .git/; cd .git/; git init --bare; cd ../../alpha/

git init; touch example1.txt (Enter text into example1.txt)

git add example1.txt; git commit -m "Initial Commit"

git remote add destination ../beta/.git; git push destination master

BLaZuRE
  • 2,295
  • 2
  • 23
  • 40
  • Please double check the described behavior. Files that are added and committed in local are immediately avaliable at remote after pushing. – Moe Apr 18 '14 at 05:47
  • @Moe Follow edited commands above. I don't see the files at remote (under beta/) after pushing. – BLaZuRE Apr 18 '14 at 06:03
  • What happens if you do a `git log` at remote after the push? – Moe Apr 18 '14 at 06:08
  • @Moe I see the commit from the local (with "Initial commit"). – BLaZuRE Apr 18 '14 at 06:08

3 Answers3

0

If you create a directory

mkdir some_dir
cd some_dir

and initialize a bare git repo,

git init --bare
git remote add origin git@github.com:username/reponame.git

then you create some files there say

echo "some_text" > somefile.txt
echo "some_text" > somefile1.txt

If you push at this stage , they wont be reflected in your remote repository.

Instead if you commit,

git add .
# Even if you push at this stage, you wont see the files in remote git server
git commit -m "Pushing to git server"

They will be reflected in the remote git server.

EDIT:

You cannot create a bare repo on the server the way you create local bare repo. It is up to the remote git server to handle this situation. For example take, github, you can create a bare repo from their UI or they provide API for that. This thread may be relevant Is it possible to create a remote repo on GitHub from the CLI without opening browser?

Community
  • 1
  • 1
Anoop
  • 4,820
  • 7
  • 33
  • 47
  • I want the *remote repo* to be bare, not the local repo. The local repo I need to be a working copy. – BLaZuRE Apr 18 '14 at 06:00
  • In response to your edit, **I am** the server, if you'd like to think of it in that sense. This is being done on a local filesystem, not via github or other git repository service. In any case, whether a bare repository can be created is not a question. Neither is the path of the remote. – BLaZuRE Apr 18 '14 at 06:07
  • In that case I am not certain how to deal with the situation. I want to know the solution too. Lets wait for the experts to answer. – Anoop Apr 18 '14 at 06:11
0

A bare repository has no checked out version and therefore will only track all files but not show them in a directory. If you want to have a folder with the latest commit of your repository checked out, I would suggest to have a detached tree that is checked out by a git hook after pushing.

See here Git Post-Receive Hook for Website Staging

Community
  • 1
  • 1
Moe
  • 1,316
  • 10
  • 13
0

Firstly, creating a bare repo within a .git folder isn't the usual best practice:

  • .git is the folder for a non-bare repo (one with a working tree located in the parent folder of the .git)
  • foo.git would be the name of the folder of a bare repo 'foo'.

Secondly, pushing to a bare repo means no files will ever "show up": a bare repo is all about avoiding synchronizing a working tree.

Instead, you can add to your bare repo a post-receive hook:

export GIT_WORK_TREE=..
git checkout -f HEAD

(as I mentioned in "Where are the project files stored in a git repository .git folder?")

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283