Lets Understand GIT

5 min readβ€’Updated recently

Git is a distributed version control system designed to help developers track changes to their codebase, collaborate with other developers, and easily revert to previous versions of their code. With Git, developers can create repositories, clone and update projects on different machines, and use branching to work on separate features or bug fixes without affecting the main codebase until they're ready to merge changes. Git is an essential tool for modern software development, enabling teams to collaborate efficiently and effectively manage codebases over time.

Pro tips: Commit small & often, write descriptive messages (consider Conventional Commits), keep feature branches short‑lived, and rebase before merging for a clean history.

Key Questions & Answers

  1. who uses git and why ?

    Git is used by a wide range of individuals and organizations, from small independent developers to large corporations. It is used by software developers and other professionals who work with code or other text-based files, such as technical writers and system administrators. There are several reasons why people use Git.

    • Git makes it easy to track changes to a codebase and collaborate with other developers. With Git, developers can easily work together on the same project without worrying about overwriting each other's changes.
    • Git also makes it easy to revert to previous versions of a codebase, which is crucial when bugs are introduced or changes need to be undone. Additionally, Git's branching system allows developers to work on separate features or bug fixes without affecting the main codebase until they're ready to merge changes.
    • Git provides a centralized location for storing code, making it easy to access and share with others. This can be particularly helpful for remote teams or those working across different time zones, as it allows everyone to stay on the same page and keep the project moving forward.
  2. why git is popular compared to its alternative subversion ?

    Git's decentralized architecture, faster performance, and more powerful branching and merging system make it more popular and better suited for modern software development workflows than Subversion. Git is more popular than Subversion for several reasons:

    • Decentralized architecture: Git has a distributed architecture, which means that every developer has a local copy of the entire codebase, including the full history of the project. This allows developers to work offline and makes it easy to collaborate with other developers, even if they are not in the same physical location. Subversion, on the other hand, has a centralized architecture, which can make it slower and more difficult to work with when dealing with large codebases or remote teams.
    • Faster performance: Git is typically faster than Subversion, especially when it comes to handling large codebases or repositories with a complex history. This is because Git stores the entire history of the project as a set of snapshots, while Subversion stores changes as a series of file differences. This makes it easier and faster to access previous versions of the codebase.
    • Branching and merging: Git's branching and merging system is more flexible and powerful than Subversion's. Git allows developers to easily create and switch between branches, making it easy to work on different features or bug fixes without affecting the main codebase. Merging branches in Git is also more intuitive and less error-prone than in Subversion.
    • Open-source community: Git has a large and active open-source community, which means that there are many resources available for learning and troubleshooting. Subversion also has an active community, but it is generally smaller and more focused on enterprise users.
  3. Does the git UI serves the same purpose compared to Git Commands ? which one is better ?

    Both Git UIs and Git commands serve the same purpose of managing the version control of a codebase. Git UIs are graphical interfaces that provide a more visual and user-friendly way of interacting with Git, while Git commands are text-based commands that are executed in the command line interface. The choice between using a Git UI or Git commands is a matter of personal preference and depends on the specific use case. Some developers prefer to use Git UIs because they offer a more visual and intuitive way of interacting with Git. Git UIs also often provide features that are not available through Git commands, such as visual diff tools and drag-and-drop merging. However, some developers prefer to use Git commands because they offer more control and flexibility over the version control process. Git commands are also often faster and more efficient than Git UIs, especially for large or complex codebases.

Common Git Commands

As a software developer, there are several Git commands that are widely used in software companies. Here are some of the most important Git commands you should learn:

git init
Initializes a new Git repository in the current directory.
git clone
Creates a local copy of a remote repository.
git add
Adds changes to the staging area.
git commit
Commits changes to the local repository.
git push
Pushes changes from the local repository to the remote repository.
git pull
Pulls changes from the remote repository to the local repository.
git branch
Lists existing branches or creates a new branch.
git checkout
Switches to a different branch or restores a file from a previous commit.
git merge
Merges changes from one branch into another.
git status
Displays the current status of the repository.
git log
Displays the commit history of the repository.
git stash
Temporarily saves changes without committing them.
git fetch
Retrieves the latest changes from a remote repository without merging them into the local repository.
git reset
Resets the repository to a previous commit, either keeping or discarding changes.
git rebase
Reapplies changes from one branch onto another branch, allowing for a cleaner, linear history.
git tag
Creates a new tag for a specific commit, allowing for easy reference to important milestones in the project.
git remote
Lists or adds a remote repository that can be used to collaborate with other developers.
git config
Displays or sets configuration options for Git, such as user name and email.
git diff
Displays the differences between the working directory and the repository.
git log --graph
Displays the commit history of the repository in a graph format, allowing for a better visualization of the branching and merging history.
Tip: Prefer git switch/git restore over legacy checkout; use git stash -p to save partial changes; and protect main with required reviews.

Conclusion

These are the most commonly used Git commands. Learning these commands and their various options will help you become more proficient in Git and improve your ability to work with others on software development projects.

Was this helpful?Suggest an edit