Skip to content

Git tools and Resources

1. GitKraken

Overview: GitKraken is a popular Git GUI tool known for its modern and intuitive interface. It provides visual tools for managing repositories, branches, and commits.

Features:

  • Visual Commit History: Interactive commit graph to visualize the repository history.
  • Drag-and-Drop Functionality: Easily move commits and branches.
  • Integrated Issue Tracking: Connects with services like GitHub, GitLab, and Bitbucket.
  • Merge Conflict Resolution: User-friendly interface for resolving conflicts.

Example:

  1. Open GitKraken.
  2. Clone a Repository:
    • Click on “Clone a repo” and enter the URL.
  3. Make Changes:
    • Use the commit panel to stage and commit changes.
  4. Push and Pull:
    • Use the toolbar to push or pull changes.

Website: GitKraken

2. SourceTree

Overview: SourceTree, developed by Atlassian, is a free Git GUI client that provides a straightforward way to interact with Git repositories.

Features:

  • Visual Branch Management: Clear visualization of branches and commits.
  • Staging and Committing: Easy staging of files and committing changes.
  • Conflict Resolution: Built-in tools for resolving merge conflicts.
  • Integration with Atlassian Products: Works well with Bitbucket and Jira.

Example:

  1. Open SourceTree.
  2. Clone a Repository:
    • Click “Clone/New” and enter the repository URL.
  3. Commit Changes:
    • Stage files in the “File Status” tab and commit changes.
  4. Push Changes:
    • Use the “Push” button in the toolbar.

Website: SourceTree

3. GitHub Desktop

Overview: GitHub Desktop is a Git GUI client developed by GitHub, designed to integrate seamlessly with GitHub repositories.

Features:

  • Simple Interface: User-friendly interface tailored for GitHub workflows.
  • Branch Management: Easy creation, switching, and merging of branches.
  • Commit Changes: Stage, commit, and push changes with ease.
  • GitHub Integration: Direct access to GitHub features and pull requests.

Example:

  1. Open GitHub Desktop.
  2. Clone a Repository:
    • Click “File” -> “Clone repository” and choose from your GitHub repositories.
  3. Commit Changes:
    • Select changes in the “Changes” tab, write a commit message, and commit.
  4. Push Changes:
    • Click the “Push origin” button.

Website: GitHub Desktop

Using Git with Integrated Development Environments (IDEs)

Section titled “Using Git with Integrated Development Environments (IDEs)”

Many IDEs offer integrated Git support, providing a seamless experience for version control directly within the development environment.

Examples:

1. Visual Studio Code (VSCode)

Overview: VSCode is a popular code editor that includes built-in Git integration.

Features:

  • Source Control Panel: View changes, stage files, and commit from the Source Control panel.
  • GitLens Extension: Enhance Git capabilities with features like blame annotations and commit history.

Example:

  1. Open VSCode.
  2. Initialize or Open a Git Repository:
    • Open a folder that contains a Git repository or initialize a new one via the Source Control icon.
  3. Stage and Commit Changes:
    • Use the Source Control panel to stage changes and commit with a message.
  4. Push and Pull:
    • Use the ellipsis menu (three dots) for push and pull actions.

Website: VSCode

2. IntelliJ IDEA

Overview: IntelliJ IDEA is a powerful IDE for Java development with comprehensive Git integration.

Features:

  • Git Tool Window: Manage branches, commits, and merges through a dedicated tool window.
  • VCS Integration: Access all Git commands through the VCS menu.

Example:

  1. Open IntelliJ IDEA.
  2. Open or Clone a Git Repository:
    • Use “File” -> “Open” to open a repository or “Get from Version Control” to clone.
  3. Commit Changes:
    • Use the “Commit” button in the VCS tool window to stage and commit changes.
  4. Push and Pull:
    • Access push and pull options from the VCS menu or tool window.

Website: IntelliJ IDEA

Purpose: git bisect helps in identifying the commit that introduced a bug by performing a binary search through the commit history.

Steps:

  1. Start Bisect:

    Terminal window
    git bisect start
  2. Mark the Bad Commit:

    Terminal window
    git bisect bad
  3. Mark a Good Commit:

    Terminal window
    git bisect good <commit-hash>
  4. Test the Intermediate Commits:

    • Git will checkout a commit between the good and bad commits.
    • Test to determine if the bug is present or not.
    • Mark the result as bad or good:
      Terminal window
      git bisect bad
      or
      Terminal window
      git bisect good
  5. Repeat Until the Problematic Commit is Found:

    • Git will continue narrowing down the range until it identifies the commit that introduced the issue.
  6. Finish Bisect:

    Terminal window
    git bisect reset

Example:

Terminal window
# Start bisecting
git bisect start
# Mark the current commit as bad
git bisect bad
# Mark an earlier commit as good
git bisect good <commit-hash>
# Test and mark intermediate commits as bad or good
# Continue until the problematic commit is found
# Reset the bisect process
git bisect reset

Purpose: Git hooks are scripts that run automatically at various points during the Git workflow. They can be used to enforce policies, automate tasks, or integrate with external tools.

Common Hooks:

  • pre-commit: Runs before a commit is made. Can be used for code linting or tests.
  • pre-push: Runs before a push to the remote repository. Useful for running tests or ensuring commit messages follow a certain format.
  • post-merge: Runs after a merge is completed. Useful for automating tasks that need to be done after a merge.

Example:

  1. Create a Hook:

    • Create a script in the .git/hooks directory, e.g., .git/hooks/pre-commit.
  2. Make the Script Executable:

    Terminal window
    chmod +x .git/hooks/pre-commit
  3. Write Hook Logic:

    # Example pre-commit hook script
    #!/bin/sh
    # Check if files match a certain format before commit
    if ! grep -q "TODO" *.txt; then
    echo "No TODOs allowed in text files."
    exit 1
    fi

Example Hook: A pre-commit hook that checks for TODO comments:

#!/bin/sh
# This hook prevents commits that contain TODO comments in code files.
if grep -r "TODO" .; then
echo "Error: TODO comments found in code files."
exit 1
fi

Submodules:

Purpose: Git submodules allow you to include and manage repositories within other repositories, useful for including external dependencies.

Commands:

  1. Add a Submodule:

    Terminal window
    git submodule add <repository-url> [path]
  2. Initialize and Update Submodules:

    Terminal window
    git submodule init
    git submodule update
  3. Remove a Submodule:

    Terminal window
    git submodule deinit -f <path>
    git rm -f <path>
    rm -rf .git/modules/<path>

Example:

Terminal window
# Add a submodule to the 'libs' directory
git submodule add https://github.com/example/libfoo.git libs/libfoo
# Initialize and update the submodule
git submodule update --init --recursive

Subtrees:

Purpose: Git subtrees allow you to merge and manage another repository within your repository, without needing to manage submodule-specific complexities.

Commands:

  1. Add a Subtree:

    Terminal window
    git subtree add --prefix=<path> <repository-url> <branch>
  2. Pull Updates from the Subtree:

    Terminal window
    git subtree pull --prefix=<path> <repository-url> <branch>
  3. Push Changes to the Subtree:

    Terminal window
    git subtree push --prefix=<path> <repository-url> <branch>

Example:

Terminal window
# Add a repository as a subtree
git subtree add --prefix=libs/lib