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?

6
  • 3
    Preparing for the outcry of all Git fans reading this in 3...2...1... ;) Commented Mar 21, 2011 at 14:14
  • 5
    If you want subversion, switch to subversion. It you want git, use git. Commented Mar 21, 2011 at 14:16
  • @David Heffernan, I would love to have the "best" of both. Commented Mar 21, 2011 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. gitref.org Commented Mar 21, 2011 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. Commented Mar 21, 2011 at 14:36

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

5 Comments

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 ?
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.
@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.
For external diff'ing, I found the answer here: stackoverflow.com/questions/255202/…. Thanks all!
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.
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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.