2

I like the simplicity of Git but I'm having a hard time using it effectively.

Is it possible to do the following with Git (on my local development machine):

  1. Have a repository in some directory like SVN (D:\gitrepo)
    • I'm afraid that I may accidentally delete my entire git repo for a project (all it takes is deleting one folder and everything is gone)
    • Having a separate out-of-the-way directory gives me some comfort.
    • It's easier to manually backup one folder rather than many
  2. Have git branches in separate directories
    • So that I can Beyond Compare them easily
    • So I can see what branches I have easily

Any suggestions on how to proceed with the above in git?

Zabba
  • 64,285
  • 47
  • 179
  • 207
  • 3
    Preparing for the outcry of all Git fans reading this in 3...2...1... ;) – musiKk Mar 21 '11 at 14:14
  • 5
    If you want subversion, switch to subversion. It you want git, use git. – David Heffernan Mar 21 '11 at 14:16
  • @David Heffernan, I would love to have the "best" of both. – Zabba Mar 21 '11 at 14:34
  • Zabba, I'd really recommend you to read some git tutorials (and git's manual pages) or you won't be able to effectively work with git, especially because you expect it to work like Subversion, which it clearly does not. E.g. http://gitref.org/ – Arc Mar 21 '11 at 14:34
  • @Archimedix, I have worked with git (though not a great deal), have read some tutorials. But these 2 things in git (esp the fact that I can't see all my branches at one go, click into the folders, etc.) were really bothering me. I do understand the differences, and appreciate git too. – Zabba Mar 21 '11 at 14:36
  • I am exactly looking for the opposite. I have to use SVN, and want to use it like GIT style..... – MOTIVECODEX Feb 18 '22 at 10:33

3 Answers3

5

To setup a repository like D:\gitrepo, you use what are called remotes. You would use this directory as a remote that you and other developers can use as the "Central SVN-like server". Create the gitrepo directory, and run the command git init --bare. Then from your local git repo you can do git remote add origin D:\gitrepo. Then you push via git push origin master. Now anyone can clone from D:\gitrepo and push their changes back up.

I'm not sure what you mean by "(all it takes is deleting one folder and everything is gone)". If you delete your src/ folder, your data isn't gone. You can easily roll it back with git reset --hard HEAD assuming you didn't commit it. If you did commit it use git revert SOMESHA. Obviously SOMESHA is the SHA1 hash for the commit. If you accidentally delete D:\gitrepo, that's not a problem because your working copy is exactly the same. Just do what I said in the first paragraph again. The only way to lose everything is if you delete the remote repository and all of the repositories cloned from it.

For backups, you just need to backup the entire D:\gitrepo folder.

For your second point, there is no easy way to have branches in separate directories. The best you can do is to have two clones, and set each clone to a different branch. I'm not familiar with Beyond Compare, but git diff works between two branches without require separate directories. Just use git diff master somebranch. To see which branches you have, use git branch

jonescb
  • 22,013
  • 7
  • 46
  • 42
  • Great! One question: Beyond Compare is a GUI tool for diff'ing, but `git diff` has only a text/command-line output .. correct? Any way to tell `git diff` to use an external program for diff'ing ? – Zabba Mar 21 '11 at 14:30
  • I think he means that if he deletes the top-level directory containing both the repository (`.git`) and his working copy, everything will be gone. – Arc Mar 21 '11 at 14:31
  • @Archimedix, yes, that's what I meant. Thus I wanted to have a out-of-the-way directory to save me grief from my delete-happy fingers. – Zabba Mar 21 '11 at 14:32
  • For external diff'ing, I found the answer here: http://stackoverflow.com/questions/255202/how-do-i-view-git-diff-output-with-visual-diff-program. Thanks all! – Zabba Mar 21 '11 at 14:35
  • If you keep more than one copy of the repository around, deleting one of them won't affect anything. Even if you delete the one acting as a central server because you can just push your copy back up to the server. – jonescb Mar 21 '11 at 15:01
2

You are definitely trying to use it in a way it wasn't designed for; that being said...

1) yes, you can have mulitiple copies of a repository around so you can 'git push' to another one as a backup if you like. Set up the other one using 'git init --bare' though.

2) You can have multiple cloned repositories next to each other and push/pull branches between them. However, in the end I think this will cause you significantly more work. 'git branch' easily lists all your available branches already.

Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69
2

For having branches in different directories, you can use the git-new-workdir script. This shares one repository between multiple working directories, which can be positioned at different branches.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210