3 Creating a New Repository

Repositories in Git are stored on your local file system right alongside the code they track. You create a repository by typing git init in the directory that you want to start tracking files in.

You use two repositories in Git to collaborate with others: a private one and a public one. Your private repository—the one we’re creating here—is where you do all your work. It’s the repository with the working tree.

This two-tier system gives you the ability to track local experimental changes while only sharing changes via your public repository that are ready for others to work with. Be careful that you don’t allow yourself to code in a cave, though. Hoarding all your changes until they are “just right” is the quickest way to harm a project. Share early; share often.

git init creates a .git directory in your current directory and initializes the Git repository inside that. Once you’ve initialized a repository, you still need to add and commit the files using git add (see Task 6, Staging Changes to Commit) and git commit (see Task 7, Committing Changes), respectively, but both of these require an initialized repository first. You have to initialize the repository only once.

Once you’ve initialized a repository, you have a working tree that you can interact with. The working tree is your view into what’s stored in your repository. It typically represents the latest copy of what’s stored in your repository.

What To Do...
  • Create a repository.
     
    prompt>​ mkdir some-repository
     
    prompt>​ cd some-repository
     
    prompt>​ git init

    For example, to create a repository called widgets in the /work directory, use this:

     
    prompt>​ mkdir /work/widgets
     
    prompt>​ cd /work/widgets
     
    prompt>​ git init
     
    Initialized empty Git repository in /work/widgets/.git/
  • Create a repository in an existing directory, and add all files from that directory.
     
    prompt>​ cd /path/to/some/directory
     
    prompt>​ git init
     
    prompt>​ git add .
     
    prompt>​ git commit -m "some commit message"

    For example, to create a repository inside an existing directory called /work/existing-widget, use this:

     
    prompt>​ cd /work/existing-widget
     
    prompt>​ git init
     
    Initialized empty Git repository in /work/existing-widget/.git/
     
    prompt>​ git add .
     
    prompt>​ git commit -m "initial commit"
     
    [master (root-commit) 6e477fa] initial commit
     
    101 files changed, 4083 insertions(+), 0 deletions(-)
     
    create mode 100644 AUTHORS
     
    ...​ and 100 more files ...

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.81