How to use GIT?

29 January 2018, in Resources
Share on Social Media: Share on facebook Share on twitter Share on google

Git is the most popular and widely used distributed version control system today. A huge number of developers rely upon Git version controlling to develop several types of commercial and non-commercial projects.

What are the advantages of Git?

  1. Easy version management of source code
  2. Easy version rollback
  3. Handle different version of codes by using Branch and Tag strategy
  4. Reduces the conflicts at collaborative environment
  5. Easy code merging
  6. Faster release cycle
  7. High availability

How to use Git?

Git has a command line interface to handle source codes. Here we are going to learn basic commands and its usage

  1. Create New Project
  2. Add New File
  3. Create Commit
  4. Create New Branch
  5. Push Branch
  6. Pull Branch
  7. Merge Branch
  8. Delete Branch

Distributed version management systems

  1. GitHub
  2. GitLab
  3. Bitbucket
1. Create New Project
We are going to create new repository by using git commands and initialize the git

mkdir gitproject
cd gitproject/
git init 
2. Add New File
Then, we are going to add new file by using following commands. So i gonna to create "test.txt" by using touch command and then added to git repo. Once you've added or modified files in a folder containing a git repo, git will notice that changes have been made inside the repo. So if you notified with changes then you must use git commit to save the local changes.
touch test.txt
git add test.txt
3.Create Commit
Commit is nothing but save option. After addition of changes you need to do git commit to save local changes using git commit command
git commit -m "Your message about the commit"

4.Create New Branch

Git branches strategy allows you to move back and forth between 'states' of a project. For example, if you want to add a new feature to your website you can create a new branch just for that feature without affecting the main part of the project. Once you're done, you can merge your changes from your branch into the master branch. And git has track of all your commits.

git branch -b branch-name

List branches 

git branch

5.Push Branch

Push command used to push your changes to origin repository. Following command will do these things

git push origin branch-name

6.Pull Branch

Pull command will used to maintain your code with origin repo. If you wants to incorporate origin changes with local repo then you must use pull command

git pull origin branch-name

7.Merge Branch

Merge can be used to merge the changes between the branches

git merge branch-name1

8. Delete Branch

Delete local branches 

git branch -d branch-name

Delete Origin branches

git push origin --delete branch-name

Here some video tutorial

Thank you