Introduction

The purpose of Git is to manage a project, or a set of files, as they change over time. Git stores this information in a data structure called a repository. The .git folder in a git repository is used by GIT programs to store information about the repository. Below example shows typical workflow of working with repositories

  1. Create a new repository
  2. Initialize repository in an existing project directory
  3. Clone a remote repository from remote
  4. Configure a Git repo for remote collaboration

Initializing Git

Assuming GIT is installed, open command line app such as terminal (on Mac) or Git bash (on Windows) and run the following commands.

  • Define the author name to be used for all commits in the current repository. Use the --global flag to set configuration options for the current user.
    git config --global user.name "John Doe"
  • Define the author email address. Adding the –local option or not passing a config level option at all, will set the user.name for the current local repository.
    git config --global user.email johndoe@example.com
    git config --local user.email johndoe@example.com
  • Set default editor git config --global core.editor Notapad++
  • Check setting git config --list
  • Seek help git help <verb>

Creating new repository

To create a new repo, use the git init command. git init is a one-time command used for the initial setup of a new repository. Executing this command will create a new .git subdirectory in current working directory, and a new master branch. Steps for creating new repository is

  1. Create a directory to contain the project.
  2. Go into the new directory.
  3. Type git init.
  4. Add file and write some code.
  5. Type git add to add the files.
  6. Type git commit to submit the changes to the repository.

If a project has already been set up in a central repository like GitHub or a similar online Git service provider,  the clone command is can be used to obtain a local development clone.

git clone https://repro-name.com/my-project my-project
git clone https://github.com/apache/poi.git my-project
cd my-project

To track an existing project by using Git, initialize a Git repository in an existing project directory. For creating git Repository for an existing project, it is as same as creating a git repository for a new project with the only difference no need to create new file. Steps for the same are

  1. Go into the directory containing the project.
  2. Type git init.
  3. Type git add to add all of the relevant files.
  4. Create a .gitignore file, to indicate all of the files you don’t want to track. Use git add .gitignore, too.
  5. Type git commit to submit the changes to the repository.