In this chapter we shall learn about following git commands:
git version
git init
git status
git config
git help
git clone
1. git version
This command is used to get the version of git installed in your PC.
2. git init
1. “git init” command is used to initiate a new GIT repository.
2. This will create a “.git” folder in the current directory.
3. It is also used to convert any directory with existing files into a GIT repository.
4. We can also use “git init <directory_name>” to create a new directory and initialize the repository.
Below is how you initialize a git repository:
Below is how the files will be visible:
3. git status
To know the status use “git status” command. Below is the output of GIT status command when used on a fresh repository.
The output will gives us “On branch master”. This is the default branch in GIT.
It also says that this is an “Initial Commit” and also “nothing to commit ” for now.
4. git config:
1. GIT Config command is used to set configuration environment. GIT stores all the configuration in “.gitconfig” file in home directory.
2. “–global” option is used to set the configuration variables global. If ignored all the configuration is set to current local repository.
3. “–system” is used to set system wide configuration, and is stored in “/etc/gitconfig”
4. “–local” is used to set the configuration locally on that directory where git is used currently and is stored in “.git/config”
4. Before we use GIT, programmer needs to set the “name” and “email” address.
To configure global username
git config --global user.name "ProDeveloperTutorial"
To configure global email address
git config --global user.email "ajay.thousand@gmail.com"
For highlighting the UI color use “color.ui” parameter:
git config --global color.ui true
For highlighting the status color use “color.status” :
git config --global color.status true
For highlighting the branch color use “color.branch” :
git config --global color.branch true
To set the default editor use “core.editor”:
git config --global core.editor gvim
To set the default merge tool use “merge.tool”
git config --global merge.tool gvimdiff
To give an alias for a command use:
git config --global alias.cmt commit
After we give an alias to a command, here we have given “cmt” for commit command. Hence we can use “git cmt” instead of “git commit” in future.
To check the list of all the configured variables use below command:
git config --global --list
5. git help
This command is used to get the help text for all the git commands.
6. git clone:
git clone is used to clone a repository into a new directory.
For example, if you want to clone linux kernel source into your local directory, use below command:
“git clone https://github.com/torvalds/linux.git”