{{announcement.body}}
{{announcement.title}}

Git: A New Way of Managing Code

DZone 's Guide to

Git: A New Way of Managing Code

Git is the superior version control system.

· Open Source Zone ·
Free Resource

The version control system is a way to manage files/directories to track file changes so that a specific version of files can be tracked later without conflicts.

Git is one of the distributed version control systems that help in:

  • Tracking code revision history
  • Sharing codebase with collaborator
  • Merging collaborators code with your code

You may also like: Top 20 Git Commands With Examples

Git was created by Linus Torvalds in 2005 using C, Shell, Perl, and Python technologies. He originally called it a ‘stupid content tracker.’ 

Advantages of Git Over Other Version Control Systems

  • Performance: In Git, code changes can be easily committed, compared, and merged. This is because Git is object-based and object formats of Git repository use several combinations of delta encoding to store metadata objects and directory contents.
  • Security: Git maintains the integrity of source code. File contents, as well as the relationship between files/directories, are secured via an algorithm which protects the code and code history against accidental damage.
  • Flexibility: Git is uniquely designed to support tagging and branching operations and store each activity carried out by the user as an integral part of “change” history.
  • Open Source: Git is a widely-used open-source version control with acceptance for more than 10 years. It is a widely-accepted system owing to its universally accepted usability and performance standards.

Disadvantages of Git

  • For doing a small operation(s), a lot of commands are needed in Git.
  • For Binary files, like images, non-text files, etc., Git becomes slow.
  • Bad command-line syntax, which is arbitrary and inconsistent.
  • For a beginner, there is a steep learning curve with so many commands and parameters.

Common Git Commands

  1.  Init: This command is used to initialize a Git repository from an existing directory of files.

Shell




x


 
1
$ git init  



2.  Clone : This command is used to get a copy of the project into your local machine.

Shell




x


 
1
$ git clone <githuburl>



3.  Status: This command is used to view the status and changes of the directory on which you are working on and staging area.

Shell




x


1
$ git status



4.  Add: This command is used to add files and directories to Git staging areas before you can commit them.

Shell




xxxxxxxxxx
1


1
 $ git add my_new_file.txt



5.  Commit: This command is used to record a snapshot of Git’s staging area.

Shell




xxxxxxxxxx
1


1
$ git commit -m “Add three files“



6.  Reset: This command is used to undo all changes and commits.

Shell




xxxxxxxxxx
1


1
$ git reset –soft HEAD^



7.  Pull: This command is used to fetch files from remote repo and try to merge with your current branch.

Shell




xxxxxxxxxx
1


1
$ git pull



8. Push: This command is used to push new branches and data in the staging area to the remote repo.

Shell




xxxxxxxxxx
1


1
$ git push -u origin master



9.  Branch: This branch is used to create, manage, and list branches.

Shell




xxxxxxxxxx
1


1
 $ git branch



10.  Checkout: This command is used to switch from one branch to another branch.

Shell




xxxxxxxxxx
1


1
$ git checkout user-profile



11. Merge: This command is used to merge a branch into your current branch.

Shell




xxxxxxxxxx
1


1
$ git merge <branchname>



Further Reading

Top 20 Git Commands With Examples

Useful Git Commands

 Commands and Operations in Git

Topics:
git and github ,git beginners guide ,git basics ,git ,os ,open source

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}