Git

Logo of Git in 2012. Source:Git
Logo of Git in 2012. Source:Git

Git (Global Information Tracker) is a popular free and open source distributed version control system for managing small to large-scale projects. It keeps track of the changes made to files in a project, making it easy to roll back when necessary. It is compatible with a wide range of operating systems and integrated development environments making it accessible to a large range of developers.

Git is a software that tracks Files and their history. Online hosting providers of git such as Github helps developers to remotely collaborate and combine each other's work.

Discussion

  • Why do developers need to learn Git?
    What is Git? Explained in 2 Minutes!. Source: Programming with Mosh.

    Git is useful for everyone from web developers to app developers who develop code or make changes to their files , if a set of people are working on one project, there is a risk of overwriting or conflicting with each others work to avoid these problems we can use Git which help teams to collaborate by implementing version control system(VCS). The most significant advantage is they can track and compare the modifications made to the files and revert back to their earlier versions if necessary.

    Version Control System (VCS) are specialized software which keeps the code in a central location and allows a team of people for sharing, collaborating and to track and make changes to their work which makes it easier to develop software in a continuous and straightforward manner.

  • What is a Git Repository?
    What is a Git Repository? [Beginner Git Tutorial]. Source: GitKraken .

    A Repository in Git stores all the project related files as well as the revised history of all the files. It is virtual storage for your projects as it creates a sub-directory named .git (Usually hidden) inside your project directory to store these files. This directory is the heart of the repository where it also tracks the changes done to the files. So that deleting the.git/ subdirectory deletes the history of your project.

    There are different ways to create a repository git init command is used to create a new repository locally and the git clone creates a local copy of a full copy of an existing repository stored on a remote server .

  • What is the difference between Bare and Non-Bare git repository?
    Comparsion of Directory structure between Bare and Non-bare repository. Source: Devopedia 2021
    Comparsion of Directory structure between Bare and Non-bare repository. Source: Devopedia 2021

    A bare repository is a git repository that is just used for collaboration among multiple individuals for push and pull, with no active development or code written directly. It can serve as a remote repository for team members to share code. Individual users may not make changes or create new versions, and it is not meant for local development .

    In a non-bare repository, files under the.git directory retain the snapshot of tracked files and allow you to edit the files under the working directory, whereas in a bare repository, you will not see the.git directory and instead all of the files that normally reside under.git will be present right over in the root directory

    Enter the command init --bare to create Bare repository. The git init command, by default, creates a non-bare repository. * Except for a few variations,both bare and non-bare repositories are almost identical .

  • What is the Difference between Git and SVN?
    Workflow of Git vs SVN. Source:  University of Washington Computer Science & Engineering community
    Workflow of Git vs SVN. Source: University of Washington Computer Science & Engineering community

    Git is a distributed version control system (DVCS) that saves a local copy of the repository on each member's machine. Any modification made to these files, referred to as a commit, is compared with the previous version and updates happen only to the alterations made in the files. Each user has their own repository as well as a working copy. Other members won't be able to see your modifications until you push changes to the central repository.

    SVN (Subversion) is a centralised version control system (CVCS) that requires individuals working on a repository to download the most recent version from a central location. Limitations of CVCS is that it need to be connected to the central repo to get the latest version of repository and also it can't perform other repo operations locally like DVCS. Despite the fact that each user has their own working copy, there is only one central repository where other members can see and update your changes as soon as you push them.

  • Tell me some interesting features of Git
    • Troubleshooting: git blame command shows line-by-line revision history done by an author. git bisect command is also used to assess good or bad commits by going throughout the project history. When we have a little idea of how a certain bug was introduced git bisect can be useful whereas git blame can be used when we couldn't find the exact cause for the problem.
    • Branching and Merging:Branches create separate copies of files in a repository for users and changes made to these files by users is not reflected on the main code and is independent of each other. This can help users to test and develop new features and commit to the main code only if required. A Sequence of commits from branches are called merging.
    • Rebasing: Changes made to the files can be replayed in the same sequence. Commits can be made on the main branch on top of other different commits made recently by another user. Each commit is made one by one so that if a conflict happens the rebasing is paused until it's fixed.
  • What is a Git workflow?
    Representation Gitflow Workflow. Source: Narongsak Keawmanee
    Representation Gitflow Workflow. Source: Narongsak Keawmanee

    It is a method of using Git in a productive and feasible manner. There are no specific rules these are some common practices and can be considered as guidelines for the development. Some commonly used workflows are described below :

    • Centralized Workflow: Similar to SVN a single collaboration model is conceptually centralized though it is decentralized technically. Though the project is contributed by multiple users there is only a single-point-of-entry for the changes made. The work done by each developer is merged before the changes are pushed no overwriting is allowed here.
    • Trunk-based development: Development happens on a single branch called Trunk the users divide work into small pieces and merged it into the trunk frequently within few hours. This also decreases the chances of merge conflicts.
    • Git Flow Workflow: There are many branches split for different purposes. Developments happen in the Develop branch with feature branches split for new features combining back to develop after getting ready. Release branch contains the code after test and is ready to be merged into the main branch. Final code ready for the release is only available in the main branch.
  • Can you describe Git add and commit?
    Workflow of Git add and Commit. Source:Maxwell Joseph, adapted from Pro Git by Chacon and Straub (2014)
    Workflow of Git add and Commit. Source:Maxwell Joseph, adapted from Pro Git by Chacon and Straub (2014)

    The Git add command includes the new or modified files in our working directory to the staging area.Files in the staging area are the ones ready to be added in the next commit. It asks Git to include these files for the upcoming commit. You can add directories, any files, even a specific part of a file. If a deleted file is added using this command then the deletion will be staged for commit.

    The term Committing is similar to saving files. Git commit would never happen without using git add for adding files to the staging area. Commits are like a recent snapshot of the repository and can show the history over a period of time. It also includes metadata like author name, timestamp etc. git revert command can be used to undo or redo a specific commit . git reset removes a specific commit and rollsback to the required commit by user . If you use git reset accidentaly and lose commits, you can use git reflog to get them back .

  • Mention the three states of Git?
    Lifecycle of Git Files. Source: Git
    Lifecycle of Git Files. Source: Git

    Git considers each file in a directory initially to be in one of two states: tracked or untracked. Files that have already been captured by git are known as tracked files. Everything else is untracked files, which are any files in your working directory not yet captured or not part of git's version control.

    These three file states are possible after the files are tracked by Git .

    • Unmodified/Modified: State of the file changes to modified whenever Files in a Repository is being edited until it is committed and stored to the local git database.
    • Staged/Staging area: When we've completed all the modifications to the files it will be moved to the staged state and is ready to be committed.
    • Committed: All modifications are saved in the local database, and the updated files are committed.
  • Can you suggest some best practices in using Git?

    Software development teams can adapt their own best practices according to their needs so there are no definite answers. Listed below are some recommended practices followed in the industry.

    • Keep the changes minimum: Use the least amount of code possible to solve an issue so it is easy to revert back if that doesn't work as expected. Git is known to have atomic behaviour means if there is an issue git will commit files partially and avoid the rest. So only one fix or one upgrade at a time is recommended
    • Writing Effective commit messages: Describe Commit messages in a meaningful way by using a verb in the present tense. Clear messages benefit both teams and self when we look back later.
    • Doing Code Reviews: Code shall be evaluated by one or a team of developers to avoid mistakes, potential bugs.
    • Make use of Branches: Branches can be used to separate work among developers for efficient workflow. Code is verified and tested before merging into the main or master branch.
  • Which should I choose Mono-Repo vs Multi-Repo?

    The term "Mono-Repository" refers to the storage of all codebase related to a project such as its libraries, dependencies, or services, in a single repository. This approach helps new contributors to make their initial setup easy since everything related to the project is stored in a single location. Deploying a component independently becomes difficult since all the files are tightly coupled with each other also the size of the repository would be huge in large projects.

    In Multi-Repository all the project related services are stored in a separate repository. Libraries, dependencies can run altogether from an isolated environment. Teams can work autonomously with different responsibilities but need to better communicate and sync to avoid breaking the code while all the work happens independently.

    There is a Multi-Mono approach known as submodules that keeps one git repository as a subdirectory of another repository.

    Though these approaches have the same goal to manage the codebase with their own benefits and drawbacks. Some challenges are managing the final release, collaborating and communication among the team. Finally, it is up to the team to decide which would suit their workflow.

Milestones

Apr
2005
Representation of Git used for Linux Kernel Project. Source: Git.Kernel.org
Representation of Git used for Linux Kernel Project. Source: Git.Kernel.org

Linus Torvalds designed the main principles of Git in a week of time to maintain the large Linux Kernel Project. Previously, a free DVCS named Bitkeeper was used until they revoked the free-of cost usage . The Word Git is a random three letter word not used by any UNIX command it doesn't have any meaning officially but can be considered as "Global information tracker" in a slang.

Jul
2005

Linus Torvalds established Git as an open source for contributions, and Junio C Hamano is designated as Git's maintainer.

Dec
2005

Git 1.0 version was launched

Jan
2006

The .dircache directory is renamed to .git which stores all the information about the repository. . A command init-db to initalize repository is changed to git-init-db.

Oct
2007
Logo of Git in 2007 Source: Git.or.cz
Logo of Git in 2007 Source: Git.or.cz

Preston-Werner and Wanstrath wish to develop a platform where where programmers could host and collaborate in Git and started working on their idea of building Github.

May
2012

Git logo was updated

Nov
2018

git range-diff command is introduced in version Version 2.19 it can be used to compare two sequences of commits and order of the changes made.

Mar
2021

git maintenance is introduced to optimize the repository data by speeding up commands and reducing the storage requirements.

References

  1. Andrews, Jeremy. 2021. "An Interview With Linus Torvalds: Linux and Git - Part 1 30 Years Of Linux." Tag1 Consulting, April 28. Accessed 2022-01-09.
  2. Arpitgoyalgg, and chrisdavidmills. 2020. "Git and GitHub - Learn web development | MDN." Mozilla developer network, September 15. Updated 2021-12-07. Accessed 2021-12-29.
  3. Atlassian. 2014. "Setting up a repository | Atlassian Git Tutorial." Atlassian, September 30. Accessed 2022-01-01.
  4. Atlassian. 2015. "Saving changes | Atlassian Git Tutorial." Atlassian. Accessed 2022-01-11.
  5. Atlassian. 2016. "What is Git and Why Should You Use it?" Atlassian. Accessed 2022-01-11.
  6. Backlog. 2020. "Git vs. SVN: Which version control system is right for you? - Backlog." Backlog.com, June 23. Accessed 2022-01-01.
  7. Bansal, Aseem. 2015. "Why are atomic commits a best practice in Git?" tothenew.com, February 15. Accessed 2022-01-05.
  8. Baudis, Petr. 2007. "Git Logo." Git, February 02. Accessed 2022-01-10.
  9. Blau, Taylor. 2018. "Highlights from Git 2.34." Github, September 18. Accessed 2022-01-12.
  10. Blau, Taylor. 2021. "Highlights from Git 2.31." Github, March 15. Accessed 2021-12-24.
  11. C Hamano, Junio. 2005. "[ANNOUNCE] GIT 1.0.0." KoreLogic, marc.info, December 12. Accessed 2022-01-10.
  12. Canonical. 2021. "git-maintenance." Ubuntu. Accessed 2022-01-11.
  13. Chacon, Scott. 2014. "1. Getting Started | 1.2 A Short History of Git." git-scm.com. Accessed 2022-01-09.
  14. Chacon, Scott, and Ben Straub. 2014. "10.1 Git Internals - Plumbing and Porcelain." git-scm.com, November. Accessed 2022-01-09.
  15. Driessen, Vincent. 2010. "A successful Git branching model." nvie.com, January 05. Accessed 2022-01-03.
  16. Ernst, Michael. 2012. "Version control concepts and best practices." University of Washington Computer Science & Engineering community., September. Updated 2021-12-20. Accessed 2022-01-01.
  17. Git. 2012. "Git - Logo Downloads." git-scm.com, May 06. Accessed 2021-12-28.
  18. Git. 2012a. "Git - git-blame Documentation." git-scm.com, May. Accessed 2022-01-02.
  19. Git. 2012b. "About - Branching and Merging." git-scm.com, May. Accessed 2022-01-03.
  20. Git. 2012c. "Logo." git-scm.com, May. Accessed 2022-01-12.
  21. Git. 2014. "Git Branching - Rebasing." git-scm.com, October. Accessed 2022-01-03.
  22. Git. 2014a. "Git - Recording Changes to the Repository." git-scm.com, October. Accessed 2022-01-03.
  23. Git. 2019. "1.3 Getting Started - What is Git? The Three States." git-scm.com, April. Accessed 2022-01-03.
  24. Git SCM. 2008. "Git Homepage." git-scm.com. Accessed 2022-01-11.
  25. Git Scm. 2012. "Git Guides." Git Scm. Accessed 2022-01-11.
  26. Git SCM. 2012. "git-reset." Git Scm. Accessed 2022-01-11.
  27. Git SCM. 2012b. "Git Revert." Git SCM. Accessed 2022-01-12.
  28. Git SCM. 2014. "7.11 Git Tools - Submodules." Git SCM. Accessed 2022-01-13.
  29. Github. 2020. "Git Guides | Git init." github.com. Accessed 2022-01-11.
  30. Github. 2020b. "Git Guides - git commit." Github. Accessed 2022-01-12.
  31. Github. 2021. "About repositories - GitHub Docs." Github. Accessed 2022-01-11.
  32. GitKraken. 2018. "What is a Git Repository? [Beginner Git Tutorial]" Youtube, April 10. Accessed 2022-01-11.
  33. gitkraken. 2021. "What is a Git Repository? | Beginner Git Tutorial." GitKraken, July 07. Accessed 2021-12-24.
  34. Gitlab. 2019. "The benefits of a distributed version control system." Gitlab, November. Accessed 2022-01-01.
  35. Gitlab. 2020. "What is version control?" GitLab, October 20. Accessed 2021-12-29.
  36. Gitlab. 2020a. "What is a Git workflow?" Gitlab, November. Accessed 2022-01-03.
  37. Gitlab. 2020b. "What are Git version control best practices?" Gitlab, November. Accessed 2022-01-05.
  38. Gitlab. 2021. "What is a centralized version control system." Gitlab, January. Accessed 2022-01-01.
  39. Gitscm. 2012. "git-init-db." git-scm.com. Accessed 2022-01-09.
  40. Gittower. 2017. "Version Control Best Practices | Learn Version Control with Git." git-tower.com, January. Accessed 2022-01-05.
  41. Google Cloud. 2021. "DevOps tech: Trunk-based development." Google Cloud. Updated 2022-01-03. Accessed 2022-01-10.
  42. Hamedani, Moshfegh. 2020. "Git Tutorial for Beginners: Learn Git in 1 Hour." Programming with Mosh, September 15. Accessed 2022-01-10.
  43. Joseph, Max. 2017. "Lesson 3. First steps with git: clone, add, commit, push Intro version control git." earthdatascience.org, September 12. Accessed 2022-01-11.
  44. Keawmanee, Narongsak. 2018. "Gitflow workflow vs Feature Branch workflow." Medium, September 22. Accessed 2022-01-03.
  45. Kernel.org. 2005. "Kernel.org git repositories." Git.kernel.org, October. Accessed 2022-01-08.
  46. King, Jeff. 2020. "Celebrating 15 years of Git: An interview with Git maintainer Junio Hamano." Github Blog, April 07. Updated 2020-05-12. Accessed 2022-01-09.
  47. Losoviz, Leonardo. 2021. "Monorepo vs Multi-Repo: Pros and Cons of Code Repository Strategies." Kinsta, August 24. Accessed 2022-01-11.
  48. Losoviz, Leonardo. 2021b. "7.11 Git Tools - Submodules." CSS-Tricks, August 17. Accessed 2022-01-13.
  49. McKenzie, Cameron. 2021. "What is a bare Git repository? - Coffee Talk: Java, News, Stories and Opinions." Tech Target, theserverside.com, May 28. Accessed 2022-01-11.
  50. mijingo. 2021. "What is a bare Git repository?" The Mijingo Blog. Accessed 2022-01-11.
  51. Noble Desktop. 2018. "What is Git and Why Should You Use it?" Noble Desktop, November 26. Updated 2021-08-24. Accessed 2021-12-28.
  52. Perforce. 2019. "5 Git Best Practices For Git Commit." Perforce, November 07. Accessed 2022-01-05.
  53. Sanket. 2019. "Best practices for using Git." Deepsource.io, February 08. Accessed 2022-01-05.
  54. Schults, Carlos. 2021. "Git Blame Explained With Examples: Who Touched the Code?" Cloudbees, October 21. Accessed 2022-01-03.
  55. serengetitech. 2020. "Three States of Git and Three Sections of a Git Project." Serengeti, March 11. Updated 2020-12-11. Accessed 2022-01-03.
  56. Shah, Hiten. 2019. "How GitHub Democratized Coding and Found a New Home at Microsoft." Nira, June 03. Updated 2020-03-13. Accessed 2022-01-10.
  57. Sheffield, Nathan. 2017. "Push-to-deploy: A nice git workflow for updating server code." databio.org, February 07. Accessed 2022-01-11.
  58. SourceLevel. 2019. "Everything about Code Review: from Peer Review to Automated Code Review." Sourcelevel.io, November 21. Updated 2021-09-22. Accessed 2022-01-05.
  59. Stopak, Jacob. 2021. "A 16 Year History Of The Git Init Command." Initial Commit, October 24. Accessed 2022-01-10.
  60. Straub, Ben, and Scott Chacon. 2014. "2.1 Git Basics - Getting a Git Repository." Apress, git-scm.com, November 12. Accessed 2022-01-11.
  61. Timoteo, Weverton. 2020. "7 Git Best Practices to Start Using in Your Next Commit." Sourcelevel.io, May 07. Updated 2020-05-18. Accessed 2022-01-05.
  62. Torvalds, Linus. 2005. "Git | README." Github, April 05. Accessed 2022-01-09.
  63. Torvalds, Linus. 2005a. "Meet the new maintainer..' - MARC." Mailing list Archives, KoreLogic, July 26. Accessed 2022-01-09.
  64. Visolyaputra, Ned. 2021. "How to choose between mono-repo and poly-repo." Accenture, January 21. Accessed 2022-01-11.
  65. Wehner, Joshua. 2015. "How to undo (almost) anything with Git." Github, June 08. Updated 2021-12-20. Accessed 2022-01-11.
  66. Özal, Serkan. 2020. "Mono- or Multi-Repository: A Dilemma in the Serverless World." Thundra.io, August. Accessed 2022-01-12.

Further Reading

  1. Git. 2012. "Reference." git-scm.com. Accessed 2022-01-10.
  2. Atlassian. 2013. "Learn Git- Git tutorials, workflows and commands | Atlassian Git Tutorial." Atlassian. Accessed 2022-01-10.
  3. Dudler, Roger. 2017. "git - the simple guide." Github. Accessed 2022-01-10.
  4. Straub, Ben, and Scott Chacon. 2014. "Pro Git." Apress, November 17. Accessed 2022-01-10.
  5. Hamedani, Moshfegh. 2020. "Git Tutorial for Beginners: Learn Git in 1 Hour." Programming with Mosh, September 15. Accessed 2022-01-10.
  6. Cottle, Peter. 2012. "Learn Git Branching." Github, August 12. Accessed 2022-01-10.

Article Stats

Author-wise Stats for Article Edits

Author
No. of Edits
No. of Chats
DevCoins
11
13
2194
1
10
416
2050
Words
0
Likes
247
Hits

Cite As

Devopedia. 2022. "Git." Version 12, January 14. Accessed 2022-01-18. https://devopedia.org/git
Contributed by
2 authors


Last updated on
2022-01-14 09:40:50