Rocheandley Kwidama


Platform Engineer @ Quintor / BSc. Network and Security Engineering
@kenepatech
Linux Enthusiast And Sometimes Windows
Audiophile

How to GIT good!

drawing

Git git git… one of the most amazing tools created to help make collaborated development easier, but can be quite tricky to get used to. That was the inspiration for me to write this post to help those who want to start, but still find it a bit of a hassle.

Git history

Git is a DevOps tool used for source control. It is a completely free and open-source version control system used to efficiently handle small to very large projects. Git is used to track changes to source code, allowing multiple developers to collaborate on nonlinear development. In fact, Linus Torvalds created Git in 2005 for the development of the Linux kernel.

Among the many version control systems available, Git has emerged as one of the most popular and powerful tools. Whether you’re a solo developer or part of a team, understanding how to use Git effectively can greatly enhance your productivity and streamline your workflow. In this blog post, we’ll walk you through the fundamentals of Git and provide a step-by-step guide on how to use it.

  1. Installing Git: To get started with Git, the first step is to install it on your local machine. Git is available for Windows, macOS, and Linux platforms. Visit the official Git website (https://git-scm.com/) and download the appropriate installer for your operating system. Once installed, you can access Git through the command line or use a graphical user interface (GUI) tool such as GitKraken or SourceTree.

  2. Initializing a Git Repository: To start using Git, you need to create a Git repository. Navigate to the directory where you want to initialize the repository and run the command git init. This creates a hidden .git directory that stores all the version control information for your project.

  3. Basic Git Workflow: The core concept of Git revolves around three main areas: the working directory, the staging area, and the repository. The typical Git workflow follows these steps:

    a. Modifying Files: Make changes to your project’s files within the working directory.

    b. Staging Changes: Use the command git add <file> to stage specific files or git add . to stage all changes. The staging area acts as a checkpoint before committing changes.

    c. Committing Changes: Create a commit to save the staged changes to the Git repository using the command git commit -m "Commit message". A commit is a snapshot of your project’s state at a particular point in time.

  4. Branching and Merging: Git allows you to create branches, which are independent lines of development. Branches enable you to work on new features or bug fixes without affecting the main codebase. To create a branch, use the command git branch <branch-name>. Switch to the new branch using git checkout <branch-name>. Once you’ve completed your changes, you can merge the branch back into the main codebase using git merge <branch-name>.

  5. Collaborating with Remote Repositories: Git facilitates collaboration by providing the ability to work with remote repositories hosted on platforms like GitHub, GitLab, or Bitbucket. To push your local repository to a remote repository, use git push <remote-name> <branch-name>. To fetch changes from a remote repository, use git fetch. To incorporate the changes into your local repository, use git merge or git pull.

  6. Resolving Conflicts: In collaborative environments, conflicts may arise when multiple developers make conflicting changes to the same file or line. Git helps you identify and resolve these conflicts. When a conflict occurs, Git marks the conflicting lines in the affected file. Manually edit the file to resolve the conflicts, then stage and commit the changes.

  7. Undoing Changes: Git provides several options to undo changes. To discard changes in the working directory, use git checkout -- <file>. To unstage changes, use git reset HEAD <file>. To revert a commit and create a new commit that undoes the changes, use git revert <commit-hash>. Be cautious when using these commands, as they modify your project’s history.

drawing

Conclusion: Git is a powerful version control system that empowers developers to manage their projects efficiently, collaborate

drawing

source: https://uidaholib.github.io/get-git/3workflow.html