[Drupal][Git] Basic gits commands to be familiar by a Drupal developer
Version control system is used to track the history of the files. Also we can revert the files to another version. Version control system will increase the potential of parallel and distributed work , ie it will track time , merge changes and manage the history of changes in the file.If you are a Drupal developer you might find Git a useful tool. Here a few commands that are to be familiar by a Drupal developer
Initialization of Git:-
Choose a path or folder to initialize git.
$ git init
The git repository is created in the path that you have given in the command prompt. It is an hidden file.
Configure your git environment:-
After initialization of git repository, you have to set up the user name, email and color that highlighted in the git console.
$ git config --global user.name “User Name”
$ git config --global user.email “User Email”
$ git config --global color.ui true
$ git config --global color.status auto
$ git config --global color.branch auto
To check the above commands you have to use the following commands.
$ git config --global --list
It will show as follows
user.name “User Name”
user.email “User Email”
color.ui true
color.status auto
color.branch auto
General Commands:-
- status
It will shows the status of the git repository. Create a file text.php and execute the following command.
$ git status
It will shows as follow
#On branch master #Untracked Files: #(use “git add ....“ to include in what will be committed ) # #text.php
- add
To add a file to git repository use the following command.
$ git add text.php
If you need to add all file the use the following command.
$ git add .
To check the added file, you have to use the status comment.
$ git status
It shows the status as follow.
#On branch master #Changes to be committed: # # (use “git reset HEAD ....“ to unstage new file : text.php
Suppose if there is any untracked files then
#Untracked Files: # (use “git add ....“ to include in what will be committed ) # # text.php
- reset
If undo the added file
$ git reset
- commit
Once you commit a added file, it will save the user name, email,time and changes in the file.
$ git commit -m “Give the related comments of the file”
It will shows as follow
[master(branch name) 14785HG(unique id)] Give the related comments of the file. 1 file changed , 1 insertion(+), 1 deletion(+) ie number of file changed, insertion ina file and deletion in file.
- diff
If you want to see the staged and unstaged changes together run the following command.
$ git diff
If you have made changes in the committed file then it will shows as follow.
diff --git a/text.php b/text.php index (some unique id) --- a/text.php +++ b/text.php ( ---changes will shown here--- )
- log
If you want to see the history of commits then run the following command.
$ git log
It will shows the history of commit with unique id, username , email and time.
- rm
If u want to removed a file from git repository use the following command.
$ git rm (path of file to be removed)
- branch
To list out branches use the following command.
$ git branch
It will list all branches and shows current branch with *.
- Create a new branch using the following command.
$ git branch testing (branch name)
- To rename a created branch.
$ git branch -m (old name) (new name)
- To delete a branch
$ git -d (branch name)
- To see the last commit on each branch.
$ git branch -v
- Create a new branch using the following command.
- checkout
- If you need to switch the branch, use the following command.
$ git checkout (branch name)
- If you need to create a branch and switched to the created branch use the following command.
$ git checkout -b (new branch name)
- Currently you are working in branch, you need to create a branch and switched to the created branch use the following command.
$ git checkout -b (new branch name) (current branch name)
- If you need to switch the branch, use the following command.
- clone
Copy a git repository.
$ git clone [url]
- push
Push the changes to the remote repository.
$ git push origin master
- shortlog
Give the changes by the author
$ git shortlog