SlideShare una empresa de Scribd logo
1 de 7
Setting uparepository
This document provides a succinct overview of the most important Git commands. First,
the Setting Up a Repository section explains all of the tools you need to start a new version-
controlled project. Then, the remaining sections introduce your everyday Git commands.
By the end of this module, you should be able to create a Git repository, record snapshots of
your project for safekeeping, and view your project’s history.
git init
The gitinit command creates a new Git repository. It can be used to convert an existing,
unversioned project to a Git repository or initialize a new empty repository. Most of the
other Git commands are not available outside of an initialized repository, so this is usually
the first command you’ll run in a new project.
Executing gitinit creates a .git subdirectory in the project root, which contains all of the
necessary metadata for the repo. Aside from the .git directory, an existing project remains
unaltered (unlike SVN, Git doesn't require a .git folder in every subdirectory).
Usage
git init
Transform the current directory into a Git repository. This adds a .git folder to the current
directory and makes it possible to start recording revisions of the project.
git init <directory>
Create an empty Git repository in the specified directory. Running this command will
create a new folder called <directorycontaining nothing but the .git subdirectory.
git init --bare <directory>
Initialize an empty Git repository, but omit the working directory. Shared repositories
should always be created with the --bareflag (see discussion below). Conventionally,
repositories initialized with the --bare flag end in .git. For example, the bare version of a
repository called my-project should be stored in a directory called my-project.git.
Discussion
Compared to SVN, the gitinit command is an incredibly easy way to create new version-
controlled projects. Git doesn’t require you to create a repository, import files, and check
out a working copy. All you have to do is cd into your project folder and run gitinit, and
you’ll have a fully functional Git repository.
However, for most projects, git init only needs to be executed once to create a central
repository—developers typically don‘t use git init to create their local repositories. Instead,
they’ll usually use gitcloneto copy an existing repository onto their local machine.
Bare Repositories
The --bareflag creates a repository that doesn’t have a working directory, making it
impossible to edit files and commit changes in that repository. Central repositories should
always be created as bare repositories because pushing branches to a non-bare repository
has the potential to overwrite changes. Think of --bareas a way to mark a repository as a
storage facility, opposed to a development environment. This means that for virtually all
Git workflows, the central repository is bare, and developers local repositories are non-
bare.
Example
Since gitcloneis a more convenient way to create local copies of a project, the most common
use case for gitinit is to create a central repository:
ssh <user>@<host>
cd path/above/repo
git init --bare my-project.git
First, you SSH into the server that will contain your central repository. Then, you navigate
to wherever you’d like to store the project. Finally, you use the --bareflag to create a central
storage repository. Developers would then [clone](/tutorials/setting-up-a-repository/git-clone)
my-project.gitto create a local copy on their development machine.
git clone
The gitclonecommand copies an existing Git repository. This is sort of like svncheckout,
except the “working copy” is a full-fledged Git repository—it has its own history, manages
its own files, and is a completely isolated environment from the original repository.
As a convenience, cloning automatically creates a remote connection called origin pointing
back to the original repository. This makes it very easy to interact with a central repository.
Usage
git clone <repo>
Clone the repository located at <repo>onto the local machine. The original repository can
be located on the local filesystem or on a remote machine accessible via HTTP or SSH.
git clone <repo> <directory>
Clone the repository located at <repo>into the folder called <directory>on the local machine.
Discussion
If a project has already been set up in a central repository, the gitclonecommand is the most
common way for users to obtain a development copy. Like gitinit, cloning is generally a one-
time operation—once a developer has obtained a working copy, all version control
operations and collaborations are managed through their local repository.
Repo-To-Repo Collaboration
It’s important to understand that Git’s idea of a “working copy” is very different from the
working copy you get by checking out code from an SVN repository. Unlike SVN, Git makes
no distinction between the working copy and the central repository—they are all full-
fledged Git repositories.
This makes collaborating with Git fundamentally different than with SVN. Whereas SVN
depends on the relationship between the central repository and the working copy, Git’s
collaboration model is based on repository-to-repository interaction. Instead of checking a
working copy into SVN’s central repository, you push orpull commits from one repository
to another.
Of course, there’s nothing stopping you from giving certain Git repos special meaning. For
example, by simply designating one Git repo as the “central” repository, it’s possible to
replicate aCentralized workflow using Git. The point is, this is accomplished through
conventions rather than being hardwired into the VCS itself.
Example
The example below demonstrates how to obtain a local copy of a central repository stored
on a server accessible at example.comusing the SSH username john:
git clone ssh://john@example.com/path/to/my-project.git
cd my-project
# Start working on the project
The first command initializes a new Git repository in the my-project folder on your local
machine and populates it with the contents of the central repository. Then, you can cdinto
the project and start editing files, committing snapshots, and interacting with other
repositories. Also note that the .gitextension is omitted from the cloned repository. This
reflects the non-bare status of the local copy.
git config
The gitconfigcommand 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.
Usage
gitconfiguser.name<name>
Define the author name to be used for all commits in the current repository. Typically,
you’ll want to use the --global flag to set configuration options for the current user.
git config --global user.name <name>
Define the author name to be used for all commits by the current user.
git config --global user.email <email>
Define the author email to be used for all commits by the current user.
git config --global alias.<alias-name> <git-command>
Create a shortcut for a Git command.
git config --system core.editor <editor>
Define the text editor used by commands like git commit for all users on the current
machine. The <editor> argument should be the command that launches the desired editor
(e.g., vi).
git config --global --edit
Open the global configuration file in a text editor for manual editing.
Discussion
All configuration options are stored in plaintext files, so the git configcommand 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 machine, and for
virtually all cases, you’ll want to use the --global flag.
Git stores configuration options in three separate files, which lets you scope options to
individual repositories, users, or the entire system:
 <repo>/.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 conflict, local settings override user settings, which override
system-wide. If you open any of these files, you’ll see something like the following:
[user]
name = John Smith
email = john@example.com
[alias]
st = status
co = checkout
br = branch
up = rebase
ci = commit
[core]
editor = vim
You can manually edit these values to the exact same effect as git config.
Example
The first thing you’ll want to do after installing Git is tell it your name/email and customize
some of the default settings. A typical initial configuration might look something like the
following:
# Tell Git who you are
git config --global user.name "John Smith"
git config --global user.email john@example.com
# Select your favorite text editor
git config --global core.editor vim
# Add 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.up rebase
git config --global alias.ci commit
This will produce the ~/.gitconfig file from the previous section.

Más contenido relacionado

La actualidad más candente

Rc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocidoRc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocido
Luis Bertel
 
Svn vs mercurial vs github
Svn  vs  mercurial vs  githubSvn  vs  mercurial vs  github
Svn vs mercurial vs github
Vinoth Kannan
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
azwildcat
 

La actualidad más candente (20)

Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Rc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocidoRc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocido
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git 101
Git 101Git 101
Git 101
 
Version controll.pptx
Version controll.pptxVersion controll.pptx
Version controll.pptx
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git and github
Git and githubGit and github
Git and github
 
Svn vs mercurial vs github
Svn  vs  mercurial vs  githubSvn  vs  mercurial vs  github
Svn vs mercurial vs github
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - Git
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Brief tutorial on Git
Brief tutorial on GitBrief tutorial on Git
Brief tutorial on Git
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git Presentation
Git PresentationGit Presentation
Git Presentation
 
Git & git hub
Git & git hubGit & git hub
Git & git hub
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 

Destacado

Flipping the Aviation Classroom Learning Environment
Flipping the Aviation Classroom Learning EnvironmentFlipping the Aviation Classroom Learning Environment
Flipping the Aviation Classroom Learning Environment
Kert Thielen
 
GonzalezCarlos CV-2016
GonzalezCarlos CV-2016GonzalezCarlos CV-2016
GonzalezCarlos CV-2016
carlosmiguelgg
 

Destacado (14)

Flipping the Aviation Classroom Learning Environment
Flipping the Aviation Classroom Learning EnvironmentFlipping the Aviation Classroom Learning Environment
Flipping the Aviation Classroom Learning Environment
 
Expansindelislam 121110172607-phpapp02
Expansindelislam 121110172607-phpapp02Expansindelislam 121110172607-phpapp02
Expansindelislam 121110172607-phpapp02
 
Business Intellenge (BI),BI Presentation
Business Intellenge (BI),BI PresentationBusiness Intellenge (BI),BI Presentation
Business Intellenge (BI),BI Presentation
 
GonzalezCarlos CV-2016
GonzalezCarlos CV-2016GonzalezCarlos CV-2016
GonzalezCarlos CV-2016
 
Business plan
Business planBusiness plan
Business plan
 
Presentación carlos alberto sandoval fdn - cci
Presentación carlos alberto sandoval   fdn - cciPresentación carlos alberto sandoval   fdn - cci
Presentación carlos alberto sandoval fdn - cci
 
Business Intellenge (BI)
Business Intellenge (BI)Business Intellenge (BI)
Business Intellenge (BI)
 
GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
E governance, Electronic Governance, Digital Governance, Digital Connection, ...
E governance, Electronic Governance, Digital Governance, Digital Connection, ...E governance, Electronic Governance, Digital Governance, Digital Connection, ...
E governance, Electronic Governance, Digital Governance, Digital Connection, ...
 
Is project failure
Is project failureIs project failure
Is project failure
 
Recycling, Reuse Reduce and Recycle
Recycling, Reuse Reduce and RecycleRecycling, Reuse Reduce and Recycle
Recycling, Reuse Reduce and Recycle
 
RETHINKING GLOBAL POVERTY (Part Two)
RETHINKING GLOBAL POVERTY (Part Two)RETHINKING GLOBAL POVERTY (Part Two)
RETHINKING GLOBAL POVERTY (Part Two)
 
RETHINKING THE WAY WE THINK
RETHINKING  THE WAY WE THINKRETHINKING  THE WAY WE THINK
RETHINKING THE WAY WE THINK
 
MASS CREATIVITY
MASS CREATIVITYMASS CREATIVITY
MASS CREATIVITY
 

Similar a setting up a repository using GIT

Similar a setting up a repository using GIT (20)

1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
 
Git Training
Git TrainingGit Training
Git Training
 
Formation git
Formation gitFormation git
Formation git
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptx
 
Git for developers
Git for developersGit for developers
Git for developers
 
GIT By Sivakrishna
GIT By SivakrishnaGIT By Sivakrishna
GIT By Sivakrishna
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git Series - Part 1
Git Series - Part 1 Git Series - Part 1
Git Series - Part 1
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Git
GitGit
Git
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
git2.ppt
git2.pptgit2.ppt
git2.ppt
 
Day 2_ Get Git with It! A Developer's Workshop.pptx
Day 2_ Get Git with It! A Developer's Workshop.pptxDay 2_ Get Git with It! A Developer's Workshop.pptx
Day 2_ Get Git with It! A Developer's Workshop.pptx
 
Brush up on using github
Brush up on using githubBrush up on using github
Brush up on using github
 
Git&GitHub.pptx
Git&GitHub.pptxGit&GitHub.pptx
Git&GitHub.pptx
 
Getting started With GIT
Getting started With GITGetting started With GIT
Getting started With GIT
 

setting up a repository using GIT

  • 1. Setting uparepository This document provides a succinct overview of the most important Git commands. First, the Setting Up a Repository section explains all of the tools you need to start a new version- controlled project. Then, the remaining sections introduce your everyday Git commands. By the end of this module, you should be able to create a Git repository, record snapshots of your project for safekeeping, and view your project’s history. git init The gitinit command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new empty repository. Most of the other Git commands are not available outside of an initialized repository, so this is usually the first command you’ll run in a new project. Executing gitinit creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repo. Aside from the .git directory, an existing project remains unaltered (unlike SVN, Git doesn't require a .git folder in every subdirectory). Usage git init Transform the current directory into a Git repository. This adds a .git folder to the current directory and makes it possible to start recording revisions of the project. git init <directory> Create an empty Git repository in the specified directory. Running this command will create a new folder called <directorycontaining nothing but the .git subdirectory. git init --bare <directory> Initialize an empty Git repository, but omit the working directory. Shared repositories should always be created with the --bareflag (see discussion below). Conventionally, repositories initialized with the --bare flag end in .git. For example, the bare version of a repository called my-project should be stored in a directory called my-project.git. Discussion Compared to SVN, the gitinit command is an incredibly easy way to create new version- controlled projects. Git doesn’t require you to create a repository, import files, and check
  • 2. out a working copy. All you have to do is cd into your project folder and run gitinit, and you’ll have a fully functional Git repository. However, for most projects, git init only needs to be executed once to create a central repository—developers typically don‘t use git init to create their local repositories. Instead, they’ll usually use gitcloneto copy an existing repository onto their local machine. Bare Repositories The --bareflag creates a repository that doesn’t have a working directory, making it impossible to edit files and commit changes in that repository. Central repositories should always be created as bare repositories because pushing branches to a non-bare repository has the potential to overwrite changes. Think of --bareas a way to mark a repository as a storage facility, opposed to a development environment. This means that for virtually all Git workflows, the central repository is bare, and developers local repositories are non- bare. Example Since gitcloneis a more convenient way to create local copies of a project, the most common use case for gitinit is to create a central repository: ssh <user>@<host> cd path/above/repo git init --bare my-project.git First, you SSH into the server that will contain your central repository. Then, you navigate to wherever you’d like to store the project. Finally, you use the --bareflag to create a central storage repository. Developers would then [clone](/tutorials/setting-up-a-repository/git-clone) my-project.gitto create a local copy on their development machine.
  • 3. git clone The gitclonecommand copies an existing Git repository. This is sort of like svncheckout, except the “working copy” is a full-fledged Git repository—it has its own history, manages its own files, and is a completely isolated environment from the original repository. As a convenience, cloning automatically creates a remote connection called origin pointing back to the original repository. This makes it very easy to interact with a central repository. Usage git clone <repo> Clone the repository located at <repo>onto the local machine. The original repository can be located on the local filesystem or on a remote machine accessible via HTTP or SSH. git clone <repo> <directory> Clone the repository located at <repo>into the folder called <directory>on the local machine. Discussion If a project has already been set up in a central repository, the gitclonecommand is the most common way for users to obtain a development copy. Like gitinit, cloning is generally a one- time operation—once a developer has obtained a working copy, all version control operations and collaborations are managed through their local repository. Repo-To-Repo Collaboration It’s important to understand that Git’s idea of a “working copy” is very different from the working copy you get by checking out code from an SVN repository. Unlike SVN, Git makes no distinction between the working copy and the central repository—they are all full- fledged Git repositories. This makes collaborating with Git fundamentally different than with SVN. Whereas SVN depends on the relationship between the central repository and the working copy, Git’s collaboration model is based on repository-to-repository interaction. Instead of checking a working copy into SVN’s central repository, you push orpull commits from one repository to another.
  • 4. Of course, there’s nothing stopping you from giving certain Git repos special meaning. For example, by simply designating one Git repo as the “central” repository, it’s possible to replicate aCentralized workflow using Git. The point is, this is accomplished through conventions rather than being hardwired into the VCS itself. Example The example below demonstrates how to obtain a local copy of a central repository stored on a server accessible at example.comusing the SSH username john: git clone ssh://john@example.com/path/to/my-project.git cd my-project # Start working on the project
  • 5. The first command initializes a new Git repository in the my-project folder on your local machine and populates it with the contents of the central repository. Then, you can cdinto the project and start editing files, committing snapshots, and interacting with other repositories. Also note that the .gitextension is omitted from the cloned repository. This reflects the non-bare status of the local copy. git config The gitconfigcommand 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. Usage gitconfiguser.name<name> Define the author name to be used for all commits in the current repository. Typically, you’ll want to use the --global flag to set configuration options for the current user. git config --global user.name <name> Define the author name to be used for all commits by the current user. git config --global user.email <email> Define the author email to be used for all commits by the current user. git config --global alias.<alias-name> <git-command> Create a shortcut for a Git command. git config --system core.editor <editor> Define the text editor used by commands like git commit for all users on the current machine. The <editor> argument should be the command that launches the desired editor (e.g., vi). git config --global --edit Open the global configuration file in a text editor for manual editing. Discussion
  • 6. All configuration options are stored in plaintext files, so the git configcommand 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 machine, and for virtually all cases, you’ll want to use the --global flag. Git stores configuration options in three separate files, which lets you scope options to individual repositories, users, or the entire system:  <repo>/.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 conflict, local settings override user settings, which override system-wide. If you open any of these files, you’ll see something like the following: [user] name = John Smith email = john@example.com [alias] st = status co = checkout br = branch up = rebase ci = commit [core] editor = vim You can manually edit these values to the exact same effect as git config. Example The first thing you’ll want to do after installing Git is tell it your name/email and customize some of the default settings. A typical initial configuration might look something like the following: # Tell Git who you are git config --global user.name "John Smith" git config --global user.email john@example.com # Select your favorite text editor
  • 7. git config --global core.editor vim # Add 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.up rebase git config --global alias.ci commit This will produce the ~/.gitconfig file from the previous section.