Skip to content

Git

https://git-scm.com/

Git is a distributed version control system (VCS) that enables developers to track changes in their codebase, collaborate with others, and manage the development of software projects. Created by Linus Torvalds, Git is known for its flexibility, speed, and efficiency. Here's an overview of key concepts and features of Git:

Key Concepts of Git:

  1. Repository (Repo):

    • A Git repository is a collection of files and directories, along with the version history of those files.
  2. Commit:

    • A commit represents a snapshot of the code at a specific point in time. Commits are used to record changes to the repository.
  3. Branch:

    • A branch is an independent line of development. Developers can create branches to work on features or fixes without affecting the main codebase.
  4. Merge:

    • Merging combines changes from different branches. This is typically done to incorporate changes made in feature branches into the main branch.
  5. Pull Request:

    • In Git-based collaboration workflows, a pull request is a way to propose changes to a codebase. It allows team members to review and discuss code changes before merging.
  6. Clone:

    • Cloning creates a copy of a repository, allowing developers to work on their local machines.
  7. Fetch and Pull:

    • Fetch retrieves changes from a remote repository, while pull combines fetching and merging to update the local repository with the latest changes.
  8. Push:

    • Push uploads local changes to a remote repository, making them accessible to other team members.
  9. Remote:

    • A remote is a connection to another Git repository. Developers can interact with remotes to fetch, pull, and push changes.
  10. Tag:

    • Tags are references that point to specific commits. They are often used to mark release points in the project's history.

Key Commands and Operations:

  1. Initialization:

    • git init: Initializes a new Git repository.
  2. Cloning:

    • git clone: Creates a copy of a remote repository on the local machine.
  3. Branching:

    • git branch: Lists existing branches.
    • git checkout -b <branch-name>: Creates and switches to a new branch.
    • git branch -d <branch-name>: Deletes a branch.
  4. Committing:

    • git add: Adds changes to the staging area.
    • git commit -m "Commit message": Commits changes to the repository.
  5. Merging:

    • git merge: Combines changes from different branches.
  6. Fetching and Pulling:

    • git fetch: Retrieves changes from a remote repository.
    • git pull: Fetches and merges changes from a remote repository.
  7. Pushing:

    • git push: Uploads local changes to a remote repository.
  8. Tagging:

    • git tag: Lists existing tags.
    • git tag -a <tag-name> -m "Tag message": Creates an annotated tag.

Resources:

  • Git Documentation: The official documentation provides comprehensive information about Git commands, workflows, and best practices.

  • Pro Git Book: "Pro Git" is a widely used book covering Git concepts and usage.

  • GitHub Learning Lab: GitHub's learning platform offers interactive courses on Git and GitHub.

  • GitHub Git Cheat Sheet: A handy cheat sheet for common Git commands.

Git is a fundamental tool for version control and collaboration in software development. Understanding its core concepts and commands is essential for effective and collaborative coding.

Common Commands

Git is a powerful version control system that allows you to track changes, collaborate with others, and manage your codebase. Here are some essential Git commands:

Configuration:

  1. Configure User Information:
    • Set your name: git config --global user.name "Your Name"
    • Set your email: git config --global user.email "your.email@example.com"

Repository Initialization:

  1. Initialize a Repository:

    • Start a new repository: git init
  2. Clone a Repository:

    • Clone an existing repository: git clone <repository-url>

Basic Workflow:

  1. Status:

    • Check the status of your repository: git status
  2. Add Changes:

    • Add changes to the staging area: git add <filename> or git add . (to add all changes)
  3. Commit Changes:

    • Commit changes with a message: git commit -m "Your commit message"
  4. Commit History:

    • View commit history: git log
  5. Branching:

    • Create a new branch: git branch <branch-name>
    • Switch to a branch: git checkout <branch-name> or git switch <branch-name>
    • Create and switch to a new branch: git checkout -b <branch-name> or git switch -c <branch-name>
  6. Merge:

    • Merge changes from one branch to another: git merge <branch-name>
  7. Delete Branch:

    • Delete a branch: git branch -d <branch-name>

Remote Repositories:

  1. Add Remote:

    • Add a remote repository: git remote add <remote-name> <repository-url>
  2. Fetch:

    • Fetch changes from a remote repository: git fetch <remote-name>
  3. Pull:

    • Pull changes from a remote repository: git pull <remote-name> <branch-name>
  4. Push:

    • Push changes to a remote repository: git push <remote-name> <branch-name>

Undo Changes:

  1. Discard Changes in Working Directory:

    • Discard local changes: git restore <filename> or git checkout -- <filename>
  2. Undo Last Commit:

    • Undo the last commit (keep changes in working directory): git reset HEAD~1
  3. Undo Last Commit Completely:

    • Undo the last commit and discard changes: git reset --hard HEAD~1

Tagging:

  1. Create Tag:

    • Create a lightweight tag: git tag <tag-name>
    • Create an annotated tag with a message: git tag -a <tag-name> -m "Tag message"
  2. Push Tag to Remote:

    • Push tags to a remote repository: git push <remote-name> --tags

Collaboration:

  1. Create Pull Request (GitHub/GitLab):

    • Create a pull request in a forked repository or branch.
  2. Fetch Pull Request Changes:

    • Fetch changes from a pull request branch: git fetch origin pull/<PR-number>/head:<local-branch-name>
  3. Cherry-Pick:

    • Apply changes from a specific commit to your current branch: git cherry-pick <commit-hash>
  4. Stash:

    • Temporarily save changes not ready for commit: git stash
    • Apply changes from the stash: git stash apply

These are some of the fundamental Git commands. Git is a versatile tool with many features, so it's advisable to refer to the official Git documentation for a comprehensive understanding of its capabilities.

Git Extensions

https://gitextensions.github.io/

"Git Extensions" is a graphical user interface (GUI) and a set of tools for managing Git repositories. It provides a convenient way for users who prefer a visual interface to interact with Git, a distributed version control system widely used for source code management.

Key features of Git Extensions include:

  1. Repository Management:

    • Create new Git repositories.
    • Clone existing repositories from remote sources.
  2. Visual Commit History:

    • View and navigate the commit history graphically.
    • See branches, commits, and their relationships.
  3. Branching and Merging:

    • Create, delete, and manage branches.
    • Perform branch merges and resolve conflicts.
  4. Tagging:

    • Create and manage tags for releases or important points in history.
  5. Stash:

    • Stash changes to temporarily save work in progress.
  6. Cherry-Picking:

    • Selectively apply specific commits to the current branch.
  7. Remote Repositories:

    • Manage remote repositories and perform fetch, pull, and push operations.
  8. Visual Diff Viewer:

    • View changes between different commits or branches visually.
  9. Git Flow Support:

    • Integration with the Git Flow branching model for feature development.
  10. Plugin System:

    • Extend functionality through plugins.
  11. Submodule Support:

    • Manage Git submodules within repositories.
  12. Visual Git Configuration:

    • Configure Git settings using a graphical interface.

Git Extensions is available for Windows and integrates with the Windows Explorer context menu, providing a seamless experience for users familiar with the Windows operating system.

Keep in mind that the features and interface may evolve, and it's always a good idea to refer to the official documentation or project page for the latest information and updates. Additionally, other Git GUI tools and IDE integrations are available, and the choice often depends on personal preferences and project requirements.

Released under the MIT License.