0

I created a repository on my vserver with

git init --bare

did the following on my local machine

git init
touch .gitignore
git add --all
git commit -m 'initial commit'

git remote add origin "git:$project_name"
git push origin master

added source files to the local project folder and commited everything (both via console and VS Code). So far, so good. Two problems:

1) The .git folder on the local machine is several times larger than the .git folder on the server. Is that normal? 2) If I clone the remote repository with another local machine, it does create lots of folders and files, but it doesn't download any source files. Are my sources not on the server at all?

gnidoc
  • 37
  • 7
  • 1
    Why do you manually initialize a second repository locally? If you'd instead clone the bare repository locally, the remote 'origin' will be automatically set by git, which makes the whole process much less error-prone. See [this answer](https://stackoverflow.com/a/27636368/1437100) for an example. – tjalling Feb 24 '20 at 14:56
  • Because that's what the official git documentation suggests: https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server – gnidoc Feb 24 '20 at 15:13
  • 1
    Interesting. It seems like a needlessly complicated way of doing things. In any case, there are several ways of inspecting things. (1) Running `git status` on your local branch should show you (in the second line of the output) whether it is _up to date with_, _ahead of_, or _behind_ the remote branch. If no remote branch is set, this line will be omitted entirely.(2) Running `git log -- path/to/mySourceFile.myExtension` will show the commit history of `mySourceFile`. If the file has not been checked in, `git log` will not print anything. – tjalling Feb 24 '20 at 15:46
  • 1
    (3) You can run a `git log` [on the remote repository](https://stackoverflow.com/a/6311945/1437100) as well. (4) Running `git status` on the second local machine will show you which branch has been checked out. (5) Running `git status` also shows you whether there are any 'untracked' (i.e. not checked into git) files or directories in the repository. Maybe did not `add` the files to git before committing? Note that you need to do (some variant of) `git add` before you do a commit, to include new files and changes to tracked files in that commit. Git wil *not* automatically track new files. – tjalling Feb 24 '20 at 15:48
  • I followed your advice and just cloned the remote rep with git clone git:project.git. I then create a file in the project folder, add it with git add * and then git commit -a. If I now delete all local files and clone the same project again, the source file is not there. – gnidoc Feb 24 '20 at 19:07
  • 1
    Did you do a `git push` after the `git commit -a`? – tjalling Feb 25 '20 at 10:17
  • 1
    Also, just to be sure, `git:project.git` is not the actual path you're using right? I assume it's simplified / anonymised for StackOverflow? As I'd expect the actual path to be more along the lines of `git://myDomain.com[:port]/path/to/repo.git/` (or by IP address, `git://192.168.0.10[:port]/path/to/repo.git/`). – tjalling Feb 25 '20 at 10:23
  • I didn't know i had to do 'git push', now it works! Another question though: git:project.git is not simplified. 'git' is an alias in .ssh/config and 'project.git' is a folder in the home-dir of the git-user on the remote machine. Should I use /home/git/project.git/ instead? – gnidoc Feb 27 '20 at 17:15
  • Yeah, due to git being distributed version control, your commits will only be in your local repository until you push your branch to the repository on the remote (i.e. on your server). It takes a bit of getting used to, but I for one really like it now. – tjalling Feb 28 '20 at 12:34
  • Regarding the `git:project.git`: so how does git on your local machine know where (i.e. on which IP address or domain) your remote machine lives? Is that part of the alias in `.ssh/config` on your local machine or something? Regarding the `project.git` vs `/home/git/project.git/`: I have no idea. I've never set up a server before - maybe there's some way to set up a default location for git repos, that in this case points to `/home/git/`. – tjalling Feb 28 '20 at 12:39
  • By the way, depending on your goals and seriousness about self-hosting a server for git, and on whether you're interested in having a web UI to browse your repository (similar to GitHub), you might want to check out running the free [self-hosted version of GitLab](https://about.gitlab.com/pricing/#self-managed) or [Gitea](https://gitea.io/). – tjalling Feb 28 '20 at 12:47

0 Answers0