2

I have used SVN for years and finally am going to switch to git. I don't understand how to do simple changes and the documentation is a bit confusing to me.

I have set up a repository in a folder called dev/ and I want to have another folder called live/ where I can update any commits I've made.

In SVN I would have done like:

svn commit dev/index.php -m "changing something"
svn up live/index.php

In git I have set up dev/, now how to I make live/? is it a clone? pull? What's the simplest way to do this?

pg.
  • 2,503
  • 4
  • 42
  • 67

2 Answers2

3

There are a bunch of tutorials that you can look up, but as someone who had worked with SVN for many years as well, I know it can be a little confusing.

There are a couple of key concepts that you've got to wrap your head around.

  1. There is a workspace which is basically where you are working with your files. This is where you're making all of your changes on your local filesystem. When you like what you've done, it's time to get to the next step.
  2. One of the biggest differences is that there is a LOCAL REPO that sits on your machine. The next step is to actually "add" your changes to the LOCAL REPO. This is done with the "git add" command. NOTE: You do need to call "add" for every file you've changed - even if it's an existing file. (Unlike SVN where you just 'add' for new files.) Git considers this as adding the file to "staging" (your local repo).
  3. When you like what you've done, you can do a "git commit" which actually marks all the changes that you've made as history in your local repo. The whole idea is that 'add' just indicates to git to watch for the changes, while commit says you're finished your changes for those files.
  4. Finally, when you're ready to actually sync your changes to the remote server repo, then you use the "git push" to actually commit it to the remote server repo.

So in your case, you'll want to go through the 3 steps above. Create your directory first. Then do the "git add" to your local repo. At this point you can start using it to add more files in that folder in your workspace. Do more "git add" for the new files you've created. When you're satisfied, do your "git commit" to commit to the local repo. Then you can push to the server repo with "git push".

It does take a little while to wrap your head around this, like I said - but it starts to feel more natural when you get into it. The whole local repo thing is really nice to be able to work offline. It also feels like a lot more commands - but they all have logical reasons. No more of the SVN commit and then "oops I forgot to add this one too" second commits - all because you can handle those things with the "git add" and double check.

Happy trails!

Shannph Wong
  • 131
  • 1
  • 5
  • You gave me a lot of info here thank you but I already checked the question which answered my narrow request. I appreciate it though and will read. – pg. Nov 12 '15 at 07:46
  • Minor point... `git add` adds *content* not *files*. If you `git add` after editing a file, the changes *so far* are staged. If you then edit the file more, and commit without doing `add` again, you'll only commit the first set of changes to the file, not the later changes. – Dan Lowe Nov 12 '15 at 16:32
  • @DanLowe Agreed. Definitely an important point when coming from SVN. Git add for all content. – Shannph Wong Nov 12 '15 at 19:48
1

You can clone dev:

cd /path/to/parent/of/dev
git clone dev live

Both dev and live represent the same Git repo on the same branch (by default master).

Since dev is purely a local repo, once you commit in dev, you need to go to live and do a git pull.

Another approach would be to consider live as an upstream repo of dev:

git init live
git clone live dev
cd dev
# work
git add . && git commit -m "message"
git push -u origin master

Then you would be able to push a commit from dev to live directly.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @pg by going to live and doing a git pull. Or by making a post-commit hook. This is because dev is purely a local repo (you don't push to an upstream repo after commit in your case) – VonC Nov 12 '15 at 07:43
  • @pg. I have edited the answer to add an alternative approach (when working with local repos) – VonC Nov 12 '15 at 07:50