I am using mingw2 under Win 10. I am barely experienced with git. I have a directory in my PC1 with several C/C++ projects. I created a git repo in PC1 with the existing files.
[PC1]$ ls -a1
./
../
.git/
.gitignore
arrays/
...
Now I mean to setup a "copy" via git in a remote computer PC2 with Ubuntu 22.04LTS to which I can connect via ssh.
I managed to git push
PC1->PC2 (see below the evidence for that). Now in PC2 I only have a .git
directory, but none of the files I actually pushed.
[PC2]$ ls -a1
./
../
.git/
I expected to see here arrays/
and other directories/files. What could the problem and solution be?
Why I infer I have "git connectivity" PC1->PC2?
To setup my repo in PC2, I executed
[PC2]$ mkdir ~/c_cpp
In the local PC1
[PC1]$ git remote add pc2 ssh://user1@pc2/home/user1/c_cpp
[PC1]$ git branch -M main
[PC1]$ git push -u pc2 main
fatal: '/home/user1/c_cpp' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
(note: pc2
is defined in ~/.ssh/config
in PC1). Guided by the error message, in PC2 I executed
[PC2]$ cd ~/c_cpp
[PC2]$ git init
and in PC1
[PC1]$ git push -u pc2 main
Enumerating objects: 96, done.
Counting objects: 100% (96/96), done.
Delta compression using up to 8 threads
Compressing objects: 100% (87/87), done.
Writing objects: 100% (96/96), 66.71 KiB | 36.00 KiB/s, done.
Total 96 (delta 20), reused 0 (delta 0), pack-reused 0
To ssh://user1@pc2/home/user1/c_cpp
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'pc2'.
To test if I have "git connectivity" PC1->PC2, I tried a couple of dummy commits, by
[PC1]$ git commit -m "dummy commit"
[PC1]$ git push -u pc2 main
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 422 bytes | 14.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0), pack-reused 0
To ssh://user1@pc2/home/user1/c_cpp
5b9b83a..13f4d01 main -> main
Branch 'main' set up to track remote branch 'main' from 'pc2'.
I repeated the procedure renaming ~/c_cpp
to ~/c_cpp.bak
in PC2, and git push
failed. After renaming back ~/c_cpp.bak
to ~/c_cpp
, git push
succeeded. Plus, the modification date of ~/c_cpp
changes with every git push
. All this works the same when using either pc2
, user1@pc2
or user1@<ip-of-pc2>
for the remote location.
So I conclude git push
is somehow working.
What happened is that on PC2, you pushed your commits into the Git repo (inside the .git
folder) but you don't have anything checked out, so you won't see the files there. If you do a git log --all
on PC2, you should see references to your commit(s).
However, it's not a very good idea to push to a regular sandbox. You'll find your life will be easier if you push to a bare repo on PC2 instead of a regular sandbox. What you did works, but it's prone to cause problems later. In particular, if you do a checkout in that repo on PC2, then you'll probably get an error when you try to push the same branch to PC2 later.
What I would recommend is that on PC2, you use git init --bare
instead of git init
for the repo there, so it's not a sandbox, but just a bare repo.
If you need to use the files on PC2 as well, clone that bare repo into a sandbox you can use normally afterwards.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.