Creating Local Git Repositories

image for 'Creating Local Git Repositories' | CAT.Models.Category

We’re in the process of evaluating several source control systems here at the office.  It’s a JOYOUS experience and I mean that… sorta.  Currently, we have a montage of files dumped into two SourceSafe repos.

Reprint from 9 November 2009 post: https://tiredblogger.wordpress.com/2009/11/09/creating-local-git-repositories-yeah-its-that-simple/

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

At this point, most of you are either laughing, crying, or have closed your web browser so you don’t get caught reading something with the word ‘SourceSafe’ in it.  That’s cool, I get that.

As part of my demonstrations (for the various toolings we’re looking at), I wanted to show how simple it was to create a local GIT repository.

Since I’m discussing ‘local’, I’m taking a lot of things out of the picture.

  • Authentication/authorization is handled by Windows file permissions/Active Directory.  If you can touch the repo and read it, then knock yourself out.
  • Everything is handled through shares, no HTTP or that goodness.  Users are used to hitting a mapped drive for SourceSafe repos, we’re just emulating that.

So what do we need to do to create a Git repository? Three easy steps (commands).

1. Create your directory with the .git extension somewhere on a network drive.

cd d:\projects

mkdir example.git

2. Change into that new directory.

cd example.git

3. Initialize the repository using Git.

git init --bare

Our new Git repository is now initalized. You can even see that PowerShell picks up on the new repository and has changed my prompt accordingly.

Now that we have example.git as our 'remote' repository, we're ready to make a local clone.

cd c:\

git clone d:\projects\example.git example

Now we have an empty clone (and it is kind enough to tell us that).

All of our Git goodness is packed into the standard .git directory.

To test things out, let's create a quick file, add it to our repo, and then commit it in.  First, let's create/append an example file to our clone.

Now let's stage our file and verify that it staged properly.

git add .

git status

Finally, let's commit and push!

git commit -am "this is our first commit!"

git push

The last step is to ensure that our new remote repository can be reproduced. HEre's a quick single line of code to clone our repository into another folder, list the contents, and verify the log has the commit we made in the first repo.

It's amazing how quick and easy it is to setup local Git repositories. From here, we can look at the file system/Windows for authentication/authorization and focus on our migration AWAY from Visual SourceSafe. :)

  • git
  • coding
  • example
  • tutorial
author photo - David Longnecker by David Longnecker

Stay Connected