Newbie using git -- need a little help

Subsystems: the rest

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Newbie using git -- need a little help

From: Robert Smith <hidden>
Date: 2016-06-15 22:43:17

Hi,

I apologize right off the bat for the stupid newbie questions.  I've read over the documentation (the full manual) numerous times and must admit it's slightly overwhelming.  What I'm trying to do is pretty basic, though, so hopefully someone can help me out.  Please forgive me for the long post (I'm going to try to describe exactly what I'm doing so that someone can point me to what I'm doing wrong).

I have both a desktop computer, a laptop, and a server where I host my git repository.  The goal for having this public repository is for me to be able to
program on my desktop, then push the changes to the server, and then
continue development on, say, my laptop later on grabbing the newer tree.  Here's what I've done so far:

On the server, I've put all my programming projects.  Then I did a:

git init && git add . && git commit -a

in one of my project directories.

I have a git-daemon running on this server so that people (me, for the most part :)) can pull my tree.

So on one of my two machines (desktop/laptop), I then clone the tree:

git clone git://my.server.com/project

It downloads the tree just fine.  Then I go into the directory and start making changes.  Here's an example:

---------------
quoted
on the desktop <<
~/temp rsmith$ git clone git://my.server.com/testing 
Initialized empty Git repository in /home/rsmith/temp/testing/.git/
remote: Generating pack...
Done counting 3 objects.
Deltifying 3 objects...
remote: /3) done
Total 3 (delta 0), reused 0 (delta 0)
Indexing 3 objects.
 100% (3/3) done

~/temp rsmith$ cd testing/

~/temp/testing rsmith$ ls
testing

~/temp/testing rsmith$ cat testing 
This is a file that was created on the repository (server) machine...

~/temp/testing rsmith$ echo "I put this line in using the client (cloned) tree...  I want to push this change up to the server that has the repo." >> testing 

~/temp/testing rsmith$ cat testing 
This is a file that was created on the repository (server) machine...
I put this line in using the client (cloned) tree...  I want to push this change up to the server that has the repo.

~/temp/testing rsmith$ git commit -a
Created commit bae2b3e9a8d939cc3982b9ab398eb398eb29a13
 1 files changed, 1 insertions(+), 0 deletions(-)

~/temp/testing rsmith$ git show
commit bae2b3e9a8d939cc3982b9ab398eb398eb29a13
Author: Robert Smith [off-list ref]
Date:   Sun Jun 17 13:54:59 2007 -0400

    Added an extra line to the file...
diff --git a/testing b/testing
index ae22fbe..bae5e8f 100644
--- a/testing
+++ b/testing
@@ -1 +1,2 @@
 This is a file that was created on the repository (server) machine...
+I put this line in using the client (cloned) tree...  I want to push this change up to the server that has the repo.

---------------
Now I push the tree up to my repository...
quoted
on the desktop <<
~/temp/testing rsmith$ git push ssh://my.server.com/scm/git/testing master
Password: 
updating 'refs/heads/master'
  from b39be3baa3b29eb39e98bd92b3ab39bee3b3a291
  to   bae2b3e9a8d939cc3982b9ab398eb398eb29a13
Generating pack...
Done counting 5 objects.
Result has 3 objects.
Deltifying 3 objects.
 100% (3/3) done
Writing 3 objects.
 100% (3/3) done
Total 3 (delta 0), reused 0 (delta 0)
Unpacking 3 objects
refs/heads/master: b39be3baa3b29eb39e98bd92b3ab39bee3b3a291 -> bae2b3e9a8d939cc3982b9ab398eb398eb29a13

---------------

Now, on the SERVER (the machine with the repository that I pushed my tree to), I can see the changes by doing a "git show"...

~/scm/git/testing rsmith$ git show
commit bae2b3e9a8d939cc3982b9ab398eb398eb29a13
Author: Robert Smith [off-list ref]
Date:   Sun Jun 17 14:22:26 2007 -0400

    Added an extra line to the file...
diff --git a/testing b/testing
index ae22fbe..bae5e8f 1206be
--- a/testing
+++ b/testing
@@ -1 +1,2 @@
 This is a file that was created on the repository machine...
+I put this line in using the client (cloned) tree...  I want to push this change up to the server that has the repo.
lines 1-13/13 (END)


HOWEVER, the testing file still doesn't show the change...  (look below)

~/scm/git/testing rsmith$ cat testing 
This is a file that was created on the repository machine...


So I figure I'll go ahead and commit the changes (since "git show" shows that the change has been pushed from the desktop to the server)...  I go ahead and do a "git commit -a" on the SERVER...

commit b3eebe298b2399238a3becc9823b3982109ebea
Author: Robert Smith [off-list ref]
Date:   Sun Jun 17 14:34:11 2007 -0400

    Testing.
diff --git a/testing b/testing
index b3ab382..3b32098a 102415
--- a/testing
+++ b/testing
@@ -1,2 +1 @@
 This is a file that was created on the repository machine...
-I put this line in using the client (cloned) tree...  I want to push this change up to the server that has the repo.

---------------
I'm not sure what I'm doing wrong.  I see the change once the tree is pushed to the server (from the desktop), but it is undone automatically with a git commit -a.  According to the documentation, everything up to the "push" step seems to be correct...  But what do I do once I pushed the tree up to the public repo?  How do I get those changes to be reflected on the public repo (the server?) without a git commit -a undoing those changes I've made?

Any ideas/help would be greatly appreciated.

- robert -




 
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121

Re: Newbie using git -- need a little help

From: Thomas Glanzmann <hidden>
Date: 2016-06-15 22:43:17

Hello Robert,
I'm not sure what I'm doing wrong.  I see the change once the tree is
pushed to the server (from the desktop), but it is undone
automatically with a git commit -a.
When you push to your server, the repository is updated (that is the
thing that is in .git) but your working tree isn't.

So when you push to a repository that also has a working tree attached
to it, you have to do a "git checkout" on the working tree. Or pull from
the repository and not push to it.

For a long time I did the same thing you did. I had a repository with a
working tree that I pushed into. I did it with bitkeeper and I did with
git. However these days I dropped that idea because it is not worth the
trouble (and it wasn't from the beginning) I just got used to it and did
not thought about it.

What I do now is the following:

On my laptop:

        mkdir dir
        git init
        # add some files
        git add .
        git commit 

Than I publish my project to the server without giving the repository at
the server a working directory attached to it. A working directory is
where you can edit files and commit changes locally, just in case I
didn't introduce the term yet.

        # This creates the repository _without_ the working tree on the server.
        ssh 131.188.30.102 git --git-dir=/home/cip/adm/sithglan/work/repositories/private/astro.git init-db

        # This adds the remote origin to the config so that I don't have to
        # type in the long repository path each time I am going to push or pull
        # something.
        git remote add origin 131.188.30.102:/home/cip/adm/sithglan/work/repositories/private/astro.git

        # Now I publish my stuff to the central repository. You need at least
        # one commit in order to be able to do that.
        git push origin master:master


        # I add a few lines to my config so that when I type in "git pull" it
        #fetches the stuff and merges it with my local repositories master branch.

        "vim .git/config" and add the following lines:

[branch "master"]
        remote = origin
        merge = refs/heads/master
EOF

        # Now I can fetch back to see if everything works
        git pull

Now I am fine the infrastructure is all set up. The next time I am going
to access the project from a different machine I simply do:

        git pull 131.188.30.102:/home/cip/adm/sithglan/work/repositories/private/astro.git

And that's it. The origin and where it is going to merge stuff is set
automatically up by git. Note: I use ssh (attached to a ssh-agent so that I
don't have to passwords all the time I am doing a push or pull). I hope that
helps you and didn't miss your original question. I just fly over your e-Mail
and picked a few keywords to comment on.

        Thomas

Re: Newbie using git -- need a little help

From: J. Bruce Fields <hidden>
Date: 2016-06-15 22:43:17

On Sun, Jun 17, 2007 at 11:55:52AM -0700, Robert Smith wrote:
I've read over the documentation (the full manual) numerous times and
must admit it's slightly overwhelming.
...
I have both a desktop computer, a laptop, and a server where I host my
git repository.  The goal for having this public repository is for me
to be able to program on my desktop, then push the changes to the
server, and then continue development on, say, my laptop later on
grabbing the newer tree.
Others answered your question, I think, so I was just trying to figure
out how to make that bit of the manual more helpful.  Do you think
something like this would have saved you any time?

--b.

(Feedback like "I tried to figure out how to do X by reading Y, and
couldn't" is much appreciated, by the way--thanks.)

---
 Documentation/user-manual.txt |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index e9da591..caa23c7 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -1772,7 +1772,7 @@ repository, but it works just as well in the other direction.
 
 If you and the maintainer both have accounts on the same machine, then
 you can just pull changes from each other's repositories directly;
-commands that accepts repository URLs as arguments will also accept a
+commands that accept repository URLs as arguments will also accept a
 local directory name:
 
 -------------------------------------------------
@@ -1780,6 +1780,15 @@ $ git clone /path/to/repository
 $ git pull /path/to/other/repository
 -------------------------------------------------
 
+or an ssh url:
+
+-------------------------------------------------
+$ git clone ssh://yourhost/~you/repository
+-------------------------------------------------
+
+For projects with few developers, or for synchronizing a few private
+repositories, this may be all you need.
+
 However, the more common way to do this is to maintain a separate public
 repository (usually on a different host) for others to pull changes
 from.  This is usually more convenient, and allows you to cleanly
@@ -1802,6 +1811,8 @@ like this:
         |               they push             V
   their public repo <------------------- their repo
 
+We explain how to do this in the following sections.
+
 [[setting-up-a-public-repository]]
 Setting up a public repository
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1913,6 +1924,12 @@ proceeding the branch name by a plus sign:
 $ git push ssh://yourserver.com/~you/proj.git +master
 -------------------------------------------------
 
+Note that the target of a "push" is normally a
+<<def_bare_repository,bare>> repository.  You can also push to a
+repository that has a checked-out working tree, but the working tree
+will not be updated by the push.  This may lead to unexpected results if
+the branch you push to is the currently checked-out branch.
+
 As with git-fetch, you may also set up configuration options to
 save typing; so, for example, after
 
-- 
1.5.2.2.238.g7cbf2f2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help