Centell
Centell

Reputation: 409

git push but does not add or change the files

I want to manage files using git(on ubuntu server). I practiced on local(mac), assuming the directory ds is the server, d1 is user1, and d2 is user2.

this is my workflow:

$ mkdir ds
$ cd ds
$ git init
$ echo '1' > 1.txt
$ git add 1.txt
$ git commit -m 'add 1.txt'
[master (root-commit) 8eab711] add 1.txt
 1 file changed, 1 insertion(+)
 create mode 100644 1.txt

and now I tried git clone:

$ cd ..
$ ls 
ds
$ git clone ds d1
$ git clone ds d2
$ ls
d1 d2 ds

Changing remote storage settings:

$ cd ds
$ git config core.bare true
$ git status
fatal: This operation must be run in a work tree

Now I tried to create file in d1.

$ cd ../d1
$ ls 
1.txt
$ echo '2' > 2.txt
$ git add 2.txt
$ git commit -m 'add 2.txt'
[master 22242b8] add 2.txt
 1 file changed, 1 insertion(+)
 create mode 100644 2.txt
$ ls
1.txt 2.txt
$ git log
commit 22242b885bbc0d2189470dd720eaf0a0a0c97ce6 (HEAD -> master)
Author: Name <[email protected]>
Date:   Thu Sep 28 10:44:48 2017 +0900

    add 2.txt

commit 8eab711880834e9e81e17d02cf6bd958e69fa58a (origin/master, origin/HEAD)
Author: Name <[email protected]>
Date:   Thu Sep 28 10:38:48 2017 +0900

    add 1.txt

I tried check git remote -v and I confirmed that there was no problem. Now I tried push!

$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 257 bytes | 257.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ..(skip)../Code/git/ds
   8eab711..22242b8  master -> master

$ls
1.txt 2.txt

now I check files on ds directory. There was a problem here.

$ cd ../ds
$ ls
1.txt

There are only '1.txt'. I checked the git log.

$ git log
commit 22242b885bbc0d2189470dd720eaf0a0a0c97ce6 (HEAD -> master)
Author: Name <[email protected]>
Date:   Thu Sep 28 10:44:48 2017 +0900

    add 2.txt

commit 8eab711880834e9e81e17d02cf6bd958e69fa58a
Author: Name <[email protected]>
Date:   Thu Sep 28 10:38:48 2017 +0900

    add 1.txt

I'm confused. In github, I remember that when I push, the file is changed.. And I tried git pull on d2 directory.

$ cd ../d2
$ ls
1.txt
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ..(skip)../Code/git/ds
   8eab711..22242b8  master     -> origin/master
Updating 8eab711..22242b8
Fast-forward
 2.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 2.txt
$ ls
1.txt   2.txt

Oh my god, 2.txt appeared.

Is the file not changing in ds? How can I keep the files in all repositories the same?

Thank you.

Upvotes: 0

Views: 283

Answers (2)

Kjwon15
Kjwon15

Reputation: 61

Bare repository has no working tree(no source files on directory) FYI: http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/ If you want to store source file on ds, Don't use bare repository.

Upvotes: 2

pishpish
pishpish

Reputation: 2614

You have to

git pull

on ds. Your local copy won't know if there's anything new on the remote unless you command it (with git fetch).

Upvotes: 1

Related Questions