banner



How To Create Git Repository In Windows

This tutorial provides an overview of how to set up upwardly a repository (repo) under Git version control. This resource will walk you lot through initializing a Git repository for a new or existing projection. Included beneath are workflow examples of repositories both created locally and cloned from remote repositories. This guide assumes a basic familiarity with a control-line interface.

video thumbnail

The high level points this guide will cover are:

  • Initializing a new Git repo
  • Cloning an existing Git repo
  • Committing a modified version of a file to the repo
  • Configuring a Git repo for remote collaboration
  • Common Git version control commands

By the end of this module, yous should be able to create a Git repo, utilise common Git commands, commit a modified file, view your project's history and configure a connection to a Git hosting service (Bitbucket).

What is a Git repository?

A Git repository is a virtual storage of your projection. It allows you to salvage versions of your code, which you can access when needed.

Initializing a new repository: git init

To create a new repo, y'all'll use the git init command. git init is a one-time command you lot employ during the initial setup of a new repo. Executing this command will create a new .git subdirectory in your current working directory. This will too create a new master co-operative.

Versioning an existing project with a new git repository

This example assumes you lot already accept an existing project folder that you would like to create a repo within. You'll first cd to the root project folder and and so execute the git init command.

            cd /path/to/your/existing/code
git init

Pointing git init to an existing projection directory will execute the aforementioned initialization setup every bit mentioned above, but scoped to that project directory.

            git init <project directory>          

Visit the git init page for a more detailed resource on git init.

Cloning an existing repository: git clone

If a project has already been set up up in a key repository, the clone command is the most common mode for users to obtain a local development clone. Like git init, cloning is generally a one-time operation. Once a programmer has obtained a working copy, all version control operations are managed through their local repository.

git clone is used to create a copy or clone of remote repositories. Y'all pass git clone a repository URL. Git supports a few different network protocols and corresponding URL formats. In this example, we'll be using the Git SSH protocol. Git SSH URLs follow a template of: git@HOSTNAME:USERNAME/REPONAME.git

An instance Git SSH URL would be: git@bitbucket.org:rhyolight/javascript-data-store.git where the template values match:

  • HOSTNAME: bitbucket.org
  • USERNAME: rhyolight
  • REPONAME: javascript-information-store

When executed, the latest version of the remote repo files on the chief branch will exist pulled down and added to a new folder. The new binder will be named after the REPONAME in this case javascript-data-store. The folder will contain the full history of the remote repository and a newly created main branch.

For more than documentation on git clone usage and supported Git URL formats, visit the git clone Page.

Saving changes to the repository: git add and git commit

Now that y'all accept a repository cloned or initialized, you can commit file version changes to it. The following example assumes you have ready up a project at /path/to/projection. The steps being taken in this example are:

  • Change directories to /path/to/projection
  • Create a new file CommitTest.txt with contents ~"exam content for git tutorial"~
  • git add CommitTest.txt to the repository staging area
  • Create a new commit with a bulletin describing what work was washed in the commit
            cd /path/to/project
echo "examination content for git tutorial" >> CommitTest.txt
git add CommitTest.txt
git commit -m "added CommitTest.txt to the repo"

After executing this instance, your repo volition now have CommitTest.txt added to the history and will track future updates to the file.

This example introduced two boosted git commands: add and commit. This was a very limited example, but both commands are covered more in depth on the git add together and git commit pages. Another common utilise instance for git add is the --all choice. Executing git add --all volition take any changed and untracked files in the repo and add them to the repo and update the repo's working tree.

Repo-to-repo collaboration: git push

It'southward important to sympathize that Git'due south idea of a "working copy" is very unlike from the working copy you get past checking out source code from an SVN repository. Unlike SVN, Git makes no distinction betwixt the working copies and the key repository—they're all full-fledged Git repositories.

This makes collaborating with Git fundamentally different than with SVN. Whereas SVN depends on the human relationship between the cardinal repository and the working copy, Git'due south collaboration model is based on repository-to-repository interaction. Instead of checking a working copy into SVN's central repository, you push or pull commits from one repository to another.

Of grade, there's null stopping you from giving certain Git repos special meaning. For example, by simply designating ane Git repo as the "primal" repository, information technology's possible to replicate a centralized workflow using Git. This is accomplished through conventions rather than existence hardwired into the VCS itself.

Bare vs. cloned repositories

If you used git clone in the previous "Initializing a new Repository" section to set up your local repository, your repository is already configured for remote collaboration. git clone volition automatically configure your repo with a remote pointed to the Git URL you lot cloned it from. This means that in one case you make changes to a file and commit them, you can git push button those changes to the remote repository.

If you used git init to make a fresh repo, y'all'll have no remote repo to push changes to. A common blueprint when initializing a new repo is to go to a hosted Git service like Bitbucket and create a repo at that place. The service will provide a Git URL that you can so add to your local Git repository and git button to the hosted repo. In one case you have created a remote repo with your service of choice you lot will demand to update your local repo with a mapping. We discuss this process in the Configuration & Prepare guide beneath.

If you prefer to host your ain remote repo, you'll demand to fix a "Blank Repository." Both git init and git clone accept a --bare argument. The near common use case for blank repo is to create a remote central Git repository

Configuration & prepare: git config

In one case you have a remote repo setup, y'all will need to add together a remote repo url to your local git config, and set an upstream branch for your local branches. The git remote command offers such utility.

            git remote add <remote_name> <remote_repo_url>          

This command will map remote repository at to a ref in your local repo under . Once you have mapped the remote repo you can button local branches to it.

            git button -u <remote_name> <local_branch_name>          

This command will button the local repo branch under < local_branch_name > to the remote repo at < remote_name >.

For more than in-depth look at git remote, meet the Git remote page.

In addition to configuring a remote repo URL, you may also need to set global Git configuration options such as username, or email. The git config command lets you configure your Git installation (or an individual repository) from the command line. This command can define everything from user info, to preferences, to the behavior of a repository. Several common configuration options are listed below.

Git stores configuration options in three dissever files, which lets y'all telescopic options to private repositories (local), user (Global), or the entire system (arrangement):

  • Local: /.git/config – Repository-specific settings.
  • Global: /.gitconfig – User-specific settings. This is where options set with the --global flag are stored.
  • System: $(prefix)/etc/gitconfig – Organization-wide settings.

Define the writer name to exist used for all commits in the current repository. Typically, you'll desire to use the --global flag to set configuration options for the current user.

            git config --global user.proper noun <name>          

Define the author proper name to be used for all commits past the current user.

Calculation the --local option or non passing a config level option at all, will set the user.name for the current local repository.

            git config --local user.email <email>          

Ascertain the author e-mail to be used for all commits by the current user.

            git config --global alias.<allonym-name> <git-command>          

Create a shortcut for a Git command. This is a powerful utility to create custom shortcuts for normally used git commands. A simplistic case would exist:

            git config --global alias.ci commit          

This creates a ci command that you lot can execute equally a shortcut to git commit. To larn more nearly git aliases visit the git config page.

            git config --system cadre.editor <editor>          

Define the text editor used by commands like git commit for all users on the current machine. The < editor > argument should exist the command that launches the desired editor (eastward.g., half-dozen). This case introduces the --system selection. The --organisation choice will set up the configuration for the entire system, meaning all users and repos on a machine. For more detailed data on configuration levels visit the git config page.

            git config --global --edit          

Open the global configuration file in a text editor for transmission editing. An in-depth guide on how to configure a text editor for git to use can exist institute on the Git config page.

Give-and-take

All configuration options are stored in plaintext files, so the git config command is really just a convenient command-line interface. Typically, you'll only need to configure a Git installation the first time you start working on a new development automobile, and for near all cases, you lot'll want to use the --global flag. Ane important exception is to override the writer email address. You may wish to set your personal email address for personal and open up source repositories, and your professional person electronic mail address for work-related repositories.

Git stores configuration options in three separate files, which lets yous scope options to individual repositories, users, or the unabridged organization:

  • /.git/config – Repository-specific settings.
  • ~/.gitconfig – User-specific settings. This is where options set with the --global flag are stored.
  • $(prefix)/etc/gitconfig – System-wide settings.

When options in these files disharmonize, local settings override user settings, which override system-wide. If you open whatsoever of these files, y'all'll see something like the following:

            [user] name = John Smith email = john@example.com [alias] st = status co = checkout br = co-operative upwards = rebase ci = commit [core] editor = vim          

You can manually edit these values to the verbal same event every bit git config.

Example

The beginning thing you'll want to exercise after installing Git is tell it your name/email and customize some of the default settings. A typical initial configuration might await something like the following:

Tell Git who y'all are git config

            git --global user.proper noun "John Smith" git config --global user.email john@example.com          

Select your favorite text editor

            git config --global core.editor vim          

Add together some SVN-like aliases

            git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.upwards rebase
git config --global alias.ci commit

This volition produce the ~ /.gitconfig file from the previous department. Take a more in-depth look at git config on the git config folio.

Summary

Here we demonstarted how to create a git repository using ii methods: git init and git clone. This guide can exist applied to manage software source code or other content that needs to exist versioned. Git add, git commit, git push, and git remote were besides introduced and utilized at a high level.

Read our guide about which code repository system is right for your team!

Source: https://www.atlassian.com/git/tutorials/setting-up-a-repository

Posted by: herreramodyette60.blogspot.com

0 Response to "How To Create Git Repository In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel