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
- Create a new repository
- Initialize repository in an existing project directory
- Clone a remote repository from remote
- 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
- Create a directory to contain the project.
- Go into the new directory.
- Type
git init
. - Add file and write some code.
- Type
git add
to add the files. - 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
- Go into the directory containing the project.
- Type
git init
. - Type
git add
to add all of the relevant files. - Create a .gitignore file, to indicate all of the files you don’t want to track. Use git add .gitignore, too.
- Type
git commit
to submit the changes to the repository.