Git 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.
Why do developers need to learn Git?
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?
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?
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. Bare Repository can be created using
git init --barecommand and if you list the contents inside the directory you can see the contents of what is normally found inside the .git directory. Individual users can't make changes or create new versions. .
In a non-bare repository, files under that reside under .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
git initcommand, 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?
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.
What is a Git workflow?
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?
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?
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.
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.
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.
- 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.
- Arpitgoyalgg, and chrisdavidmills. 2020. "Git and GitHub - Learn web development | MDN." Mozilla developer network, September 15. Updated 2021-12-07. Accessed 2021-12-29.
- Atlassian. 2014. "Setting up a repository | Atlassian Git Tutorial." Atlassian, September 30. Accessed 2022-01-01.
- Atlassian. 2015. "Saving changes | Atlassian Git Tutorial." Atlassian. Accessed 2022-01-11.
- Atlassian. 2016. "What is Git and Why Should You Use it?" Atlassian. Accessed 2022-01-11.
- Backlog. 2020. "Git vs. SVN: Which version control system is right for you? - Backlog." Backlog.com, June 23. Accessed 2022-01-01.
- Bansal, Aseem. 2015. "Why are atomic commits a best practice in Git?" tothenew.com, February 15. Accessed 2022-01-05.
- Baudis, Petr. 2007. "Git Logo." Git, February 02. Accessed 2022-01-10.
- Blau, Taylor. 2018. "Highlights from Git 2.34." Github, September 18. Accessed 2022-01-12.
- Blau, Taylor. 2021. "Highlights from Git 2.31." Github, March 15. Accessed 2021-12-24.
- C Hamano, Junio. 2005. "[ANNOUNCE] GIT 1.0.0." KoreLogic, marc.info, December 12. Accessed 2022-01-10.
- Canonical. 2021. "git-maintenance." Ubuntu. Accessed 2022-01-11.
- Chacon, Scott. 2014. "1. Getting Started | 1.2 A Short History of Git." git-scm.com. Accessed 2022-01-09.
- Chacon, Scott, and Ben Straub. 2014. "10.1 Git Internals - Plumbing and Porcelain." git-scm.com, November. Accessed 2022-01-09.
- Driessen, Vincent. 2010. "A successful Git branching model." nvie.com, January 05. Accessed 2022-01-03.
- 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.
- Git. 2012. "Git - Logo Downloads." git-scm.com, May 06. Accessed 2021-12-28.
- Git. 2012a. "Git - git-blame Documentation." git-scm.com, May. Accessed 2022-01-02.
- Git. 2012b. "About - Branching and Merging." git-scm.com, May. Accessed 2022-01-03.
- Git. 2012c. "Logo." git-scm.com, May. Accessed 2022-01-12.
- Git. 2014. "Git Branching - Rebasing." git-scm.com, October. Accessed 2022-01-03.
- Git. 2014a. "Git - Recording Changes to the Repository." git-scm.com, October. Accessed 2022-01-03.
- Git. 2019. "1.3 Getting Started - What is Git? The Three States." git-scm.com, April. Accessed 2022-01-03.
- Git SCM. 2008. "Git Homepage." git-scm.com. Accessed 2022-01-11.
- Git SCM. 2012. "git-reset." Git Scm. Accessed 2022-01-11.
- Git SCM. 2012b. "Git Revert." Git SCM. Accessed 2022-01-12.
- Git SCM. 2014. "7.11 Git Tools - Submodules." Git SCM. Accessed 2022-01-13.
- Git Scm. 2012. "Git Guides." Git Scm. Accessed 2022-01-11.
- GitKraken. 2018. "What is a Git Repository? [Beginner Git Tutorial]" Youtube, April 10. Accessed 2022-01-11.
- Github. 2020. "Git Guides | Git init." github.com. Accessed 2022-01-11.
- Github. 2020b. "Git Guides - git commit." Github. Accessed 2022-01-12.
- Github. 2021. "About repositories - GitHub Docs." Github. Accessed 2022-01-11.
- Gitlab. 2019. "The benefits of a distributed version control system." Gitlab, November. Accessed 2022-01-01.
- Gitlab. 2020. "What is version control?" GitLab, October 20. Accessed 2021-12-29.
- Gitlab. 2020a. "What is a Git workflow?" Gitlab, November. Accessed 2022-01-03.
- Gitlab. 2020b. "What are Git version control best practices?" Gitlab, November. Accessed 2022-01-05.
- Gitlab. 2021. "What is a centralized version control system." Gitlab, January. Accessed 2022-01-01.
- Gitscm. 2012. "git-init-db." git-scm.com. Accessed 2022-01-09.
- Gittower. 2017. "Version Control Best Practices | Learn Version Control with Git." git-tower.com, January. Accessed 2022-01-05.
- Google Cloud. 2021. "DevOps tech: Trunk-based development." Google Cloud. Updated 2022-01-03. Accessed 2022-01-10.
- Hamedani, Moshfegh. 2020. "Git Tutorial for Beginners: Learn Git in 1 Hour." Programming with Mosh, September 15. Accessed 2022-01-10.
- 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.
- Keawmanee, Narongsak. 2018. "Gitflow workflow vs Feature Branch workflow." Medium, September 22. Accessed 2022-01-03.
- Kernel.org. 2005. "Kernel.org git repositories." Git.kernel.org, October. Accessed 2022-01-08.
- 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.
- Losoviz, Leonardo. 2021. "Monorepo vs Multi-Repo: Pros and Cons of Code Repository Strategies." Kinsta, August 24. Accessed 2022-01-11.
- Losoviz, Leonardo. 2021b. "7.11 Git Tools - Submodules." CSS-Tricks, August 17. Accessed 2022-01-13.
- 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.
- Noble Desktop. 2018. "What is Git and Why Should You Use it?" Noble Desktop, November 26. Updated 2021-08-24. Accessed 2021-12-28.
- Perforce. 2019. "5 Git Best Practices For Git Commit." Perforce, November 07. Accessed 2022-01-05.
- Sanket. 2019. "Best practices for using Git." Deepsource.io, February 08. Accessed 2022-01-05.
- Schults, Carlos. 2021. "Git Blame Explained With Examples: Who Touched the Code?" Cloudbees, October 21. Accessed 2022-01-03.
- 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.
- Sheffield, Nathan. 2017. "Push-to-deploy: A nice git workflow for updating server code." databio.org, February 07. Accessed 2022-01-11.
- 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.
- Stopak, Jacob. 2021. "A 16 Year History Of The Git Init Command." Initial Commit, October 24. Accessed 2022-01-10.
- Straub, Ben, and Scott Chacon. 2014. "2.1 Git Basics - Getting a Git Repository." Apress, git-scm.com, November 12. Accessed 2022-01-11.
- 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.
- Torvalds, Linus. 2005. "Git | README." Github, April 05. Accessed 2022-01-09.
- Torvalds, Linus. 2005a. "Meet the new maintainer..' - MARC." Mailing list Archives, KoreLogic, July 26. Accessed 2022-01-09.
- Visolyaputra, Ned. 2021. "How to choose between mono-repo and poly-repo." Accenture, January 21. Accessed 2022-01-11.
- Wehner, Joshua. 2015. "How to undo (almost) anything with Git." Github, June 08. Updated 2021-12-20. Accessed 2022-01-11.
- gitkraken. 2021. "What is a Git Repository? | Beginner Git Tutorial." GitKraken, July 07. Accessed 2021-12-24.
- mijingo. 2021. "What is a bare Git repository?" The Mijingo Blog. Accessed 2022-01-11.
- serengetitech. 2020. "Three States of Git and Three Sections of a Git Project." Serengeti, March 11. Updated 2020-12-11. Accessed 2022-01-03.
- Özal, Serkan. 2020. "Mono- or Multi-Repository: A Dilemma in the Serverless World." Thundra.io, August. Accessed 2022-01-12.
- Git. 2012. "Reference." git-scm.com. Accessed 2022-01-10.
- Atlassian. 2013. "Learn Git- Git tutorials, workflows and commands | Atlassian Git Tutorial." Atlassian. Accessed 2022-01-10.
- Dudler, Roger. 2017. "git - the simple guide." Github. Accessed 2022-01-10.
- Straub, Ben, and Scott Chacon. 2014. "Pro Git." Apress, November 17. Accessed 2022-01-10.
- Hamedani, Moshfegh. 2020. "Git Tutorial for Beginners: Learn Git in 1 Hour." Programming with Mosh, September 15. Accessed 2022-01-10.
- Cottle, Peter. 2012. "Learn Git Branching." Github, August 12. Accessed 2022-01-10.
- Version Control
- Git Internals
- Continuous Delivery
- Semantic Versioning
- Conventional Commits