randomblink
randomblink

Reputation: 235

Use Git to create copy of directory at remote location

I am completely new to Git. What I am trying to do is wrap my head around some Git concepts. As a test, I want a simple thing. I will manually create a folder called TEST on my local computer at: C:\GIT_Test and then place a file or files in that folder.

Now I want to create a folder called C:\GIT_OtherTest and using Git send the contents of C:\GIT_Test to C:\GIT_OtherTest.

What commands would I need to know to do this?

Upvotes: 0

Views: 47

Answers (1)

Max
Max

Reputation: 22365

You cannot do this exactly as you described it. That is because Git is a distributed version control system. That matters in this case because in a distributed system you cannot push your changes on others -- instead they decide when to pull changes from you.

Here's how that would work (using command line git)

cd GIT_Test
git init .
mkdir TEST
touch TEST/foo
git add TEST/foo
git commit -m "Added testing file"

cd ../GIT_OtherTest
git init .
git remote add test ../GIT_Test
git pull test master

The one exception to this is bare repositories. Bare repositories don't have working copies of the files so you can safely push to them without overwriting anyone's work. The downside is that you can't work on files in a bare repository directly - you must clone the repository and make changes there.

For example, we could have done the second part differently up there:

cd ..
git init --bare GIT_Central

cd GIT_Test
git remote add central ../GIT_Central
git push central master
ls ../GIT_Central # notice how this doesn't actually contain the files we pushed

cd ..
git clone GIT_Central GIT_OtherTest
ls GIT_OtherTest # but here they are!

So the commands you need to know are init, add, commit, remote, pull, push, and clone.

Upvotes: 2

Related Questions