Convert Figma logo to code with AI

agis logogit-style-guide

A Git Style Guide

5,082
423
5,082
0

Top Related Projects

9,452

A guide for programming in style.

A guide to understand the importance of commit messages and how to write them well

A markdown version emoji cheat sheet

Flight rules for git

160,973

A collection of useful .gitignore templates

Quick Overview

The agis/git-style-guide repository provides a comprehensive set of guidelines and best practices for using Git, the popular distributed version control system. The guide covers various aspects of Git usage, from commit messages and branching strategies to repository management and collaboration.

Pros

  • Comprehensive Coverage: The guide covers a wide range of Git-related topics, making it a valuable resource for both beginners and experienced Git users.
  • Community-Driven: The guide is maintained by the open-source community, ensuring that it stays up-to-date and reflects the latest best practices.
  • Customizable: The guide can be easily customized to fit the specific needs of a team or organization.
  • Promotes Consistency: By following the guidelines, teams can maintain a consistent Git workflow, improving collaboration and code maintainability.

Cons

  • Opinionated: The guide presents a specific set of recommendations, which may not align with the preferences or existing workflows of all teams or organizations.
  • Requires Adaptation: Adopting the guidelines may require some effort to integrate them into an existing Git workflow, especially for teams with well-established practices.
  • Potential Outdated Information: As with any community-driven project, there is a risk of the guide containing outdated information or not keeping up with the latest Git features and best practices.
  • Lack of Detailed Explanations: While the guide provides a comprehensive set of guidelines, it may not always offer in-depth explanations for the reasoning behind certain recommendations.

Competitor Comparisons

9,452

A guide for programming in style.

Pros of guides

  • Comprehensive coverage of multiple languages and tools
  • Regularly updated with contributions from the community
  • Includes best practices for project management and workflow

Cons of guides

  • Less focused on Git-specific practices
  • May be overwhelming for beginners due to its broad scope
  • Some guidelines may be opinionated or specific to thoughtbot's workflow

Code Comparison

git-style-guide:

# Good
git checkout -b feature-branch

# Bad
git checkout -b feature_branch

guides:

# Good
def some_method
  do_something
end

# Bad
def some_method
    do_something
end

Summary

git-style-guide focuses specifically on Git best practices, providing a concise and targeted guide for Git usage. It's ideal for developers looking to improve their Git workflow.

guides offers a broader set of best practices covering multiple languages and development aspects. It's more suitable for teams or individuals seeking comprehensive guidance across various development areas.

Both repositories provide valuable insights, but they serve different purposes. git-style-guide is more specialized, while guides offers a wider range of development best practices.

A guide to understand the importance of commit messages and how to write them well

Pros of commit-messages-guide

  • More comprehensive coverage of commit message best practices
  • Includes examples of good and bad commit messages
  • Provides explanations for each guideline, enhancing understanding

Cons of commit-messages-guide

  • Focuses solely on commit messages, lacking broader Git workflow guidance
  • Less structured format compared to git-style-guide
  • Doesn't cover branch naming conventions or other Git-related topics

Code Comparison

commit-messages-guide example:

feat: add hat wobble
^--^  ^------------^
|     |
|     +-> Summary in present tense
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test

git-style-guide example:

Summarize changes in around 50 characters or less

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.

Both repositories provide valuable guidance for Git users, but they focus on different aspects. commit-messages-guide offers in-depth advice on crafting effective commit messages, while git-style-guide covers a broader range of Git practices. Users may benefit from consulting both resources for a comprehensive understanding of Git best practices.

A markdown version emoji cheat sheet

Pros of emoji-cheat-sheet

  • Comprehensive list of emojis with easy-to-copy codes
  • Regularly updated with new emoji additions
  • Includes search functionality for quick emoji lookup

Cons of emoji-cheat-sheet

  • Lacks guidelines for proper emoji usage in commit messages
  • Not specifically tailored for Git or version control practices
  • May encourage overuse of emojis in professional contexts

Code comparison

emoji-cheat-sheet:

| :bowtie: `:bowtie:` | :smile: `:smile:` | :laughing: `:laughing:` |
|---|---|---|
| :blush: `:blush:` | :smiley: `:smiley:` | :relaxed: `:relaxed:` |

git-style-guide:

# Git Style Guide

## Table of Contents

  1. [Branches](#branches)
  2. [Commits](#commits)
  3. [Messages](#messages)

Summary

While emoji-cheat-sheet provides a comprehensive reference for emoji codes, git-style-guide offers specific guidelines for Git usage. emoji-cheat-sheet is more focused on emoji representation, while git-style-guide provides best practices for version control workflows. The choice between the two depends on whether you need emoji references or Git usage guidelines.

Flight rules for git

Pros of git-flight-rules

  • More comprehensive, covering a wide range of Git scenarios and problems
  • Provides step-by-step solutions for specific Git issues
  • Regularly updated with contributions from the community

Cons of git-flight-rules

  • Less focused on establishing a consistent Git workflow
  • May be overwhelming for beginners due to its extensive content
  • Lacks concise style guidelines for commit messages and branch naming

Code comparison

git-flight-rules:

git config --global alias.undo-commit 'reset --soft HEAD^'
git config --global alias.amend 'commit --amend --no-edit'

git-style-guide:

# Good
git commit -m "Add feature X"

# Bad
git commit -m "Added feature X"

Summary

git-flight-rules is a comprehensive resource for troubleshooting Git issues, offering detailed solutions for various scenarios. It's particularly useful for developers facing specific Git problems. On the other hand, git-style-guide focuses on establishing consistent Git practices and workflows, providing concise guidelines for commit messages and branch naming. While git-flight-rules is more extensive and regularly updated, git-style-guide offers a more streamlined approach to maintaining a consistent Git workflow across projects and teams.

160,973

A collection of useful .gitignore templates

Pros of gitignore

  • Comprehensive collection of .gitignore templates for various languages and frameworks
  • Actively maintained with frequent updates and contributions
  • Widely adopted and recognized as a standard resource for .gitignore files

Cons of gitignore

  • Focused solely on .gitignore files, lacking broader Git best practices
  • May include unnecessary patterns for specific projects, requiring customization
  • Limited explanations or context for included patterns

Code comparison

git-style-guide:

# 1.6 Protect the develop and master branches
To protect the main branches, namely `develop` and `master`, from unwanted changes, force push should be disabled.

gitignore:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

Summary

While gitignore provides an extensive collection of .gitignore templates, git-style-guide offers a broader set of Git best practices and conventions. gitignore is more focused on practical file exclusion patterns, whereas git-style-guide provides guidance on Git workflow and repository management. Both repositories serve different purposes and can be complementary in a developer's toolkit.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Git Style Guide

This is a Git Style Guide inspired by How to Get Your Change Into the Linux Kernel, the git man pages and various practices popular among the community.

Translations are available in the following languages:

If you feel like contributing, please do so! Fork the project and open a pull request.

Table of contents

  1. Branches
  2. Commits
  3. Messages
  4. Merging
  5. Misc.

Branches

  • Choose short and descriptive names:

    # good
    $ git checkout -b oauth-migration
    
    # bad - too vague
    $ git checkout -b login_fix
    
  • Identifiers from corresponding tickets in an external service (eg. a GitHub issue) are also good candidates for use in branch names. For example:

    # GitHub issue #15
    $ git checkout -b issue-15
    
  • Use lowercase in branch names. External ticket identifiers with uppercase letters are a valid exception. Use hyphens to separate words.

    $ git checkout -b new-feature      # good
    $ git checkout -b T321-new-feature # good (Phabricator task id)
    $ git checkout -b New_Feature      # bad
    
  • When several people are working on the same feature, it might be convenient to have personal feature branches and a team-wide feature branch. Use the following naming convention:

    $ git checkout -b feature-a/main # team-wide branch
    $ git checkout -b feature-a/maria  # Maria's personal branch
    $ git checkout -b feature-a/nick   # Nick's personal branch
    

    Merge at will the personal branches to the team-wide branch (see "Merging"). Eventually, the team-wide branch will be merged to "main".

  • Delete your branch from the upstream repository after it's merged, unless there is a specific reason not to.

    Tip: Use the following command while being on "main", to list merged branches:

    $ git branch --merged | grep -v "\*"
    

Commits

  • Each commit should be a single logical change. Don't make several logical changes in one commit. For example, if a patch fixes a bug and optimizes the performance of a feature, split it into two separate commits.

    Tip: Use git add -p to interactively stage specific portions of the modified files.

  • Don't split a single logical change into several commits. For example, the implementation of a feature and the corresponding tests should be in the same commit.

  • Commit early and often. Small, self-contained commits are easier to understand and revert when something goes wrong.

  • Commits should be ordered logically. For example, if commit X depends on changes done in commit Y, then commit Y should come before commit X.

Note: While working alone on a local branch that has not yet been pushed, it's fine to use commits as temporary snapshots of your work. However, it still holds true that you should apply all of the above before pushing it.

Messages

  • Use the editor, not the terminal, when writing a commit message:

    # good
    $ git commit
    
    # bad
    $ git commit -m "Quick fix"
    

    Committing from the terminal encourages a mindset of having to fit everything in a single line which usually results in non-informative, ambiguous commit messages.

  • The summary line (ie. the first line of the message) should be descriptive yet succinct. Ideally, it should be no longer than 50 characters. It should be capitalized and written in imperative present tense. It should not end with a period since it is effectively the commit title:

    # good - imperative present tense, capitalized, fewer than 50 characters
    Mark huge records as obsolete when clearing hinting faults
    
    # bad
    fixed ActiveModel::Errors deprecation messages failing when AR was used outside of Rails.
    
  • After that should come a blank line followed by a more thorough description. It should be wrapped to 72 characters and explain why the change is needed, how it addresses the issue and what side-effects it might have.

    It should also provide any pointers to related resources (eg. link to the corresponding issue in a bug tracker):

    Short (50 chars or fewer) summary of changes
    
    More detailed explanatory text, if necessary. Wrap it to
    72 characters. In some contexts, the first
    line is treated as the subject of an email and the rest of
    the text as the body.  The blank line separating the
    summary from the body is critical (unless you omit the body
    entirely); tools like rebase can get confused if you run
    the two together.
    
    Further paragraphs come after blank lines.
    
    - Bullet points are okay, too
    
    - Use a hyphen or an asterisk for the bullet,
      followed by a single space, with blank lines in
      between
    
    The pointers to your related resources can serve as a footer
    for your commit message. Here is an example that is referencing
    issues in a bug tracker:
    
    Resolves: #56, #78
    See also: #12, #34
    
    Source: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
    

    Ultimately, when writing a commit message, think about what you would need to know if you run across the commit in a year from now.

  • If a commit A depends on commit B, the dependency should be stated in the message of commit A. Use the SHA1 when referring to commits.

    Similarly, if commit A solves a bug introduced by commit B, it should also be stated in the message of commit A.

  • If a commit is going to be squashed to another commit use the --squash and --fixup flags respectively, in order to make the intention clear:

    $ git commit --squash f387cab2
    

    (Tip: Use the --autosquash flag when rebasing. The marked commits will be squashed automatically.)

Merging

  • Do not rewrite published history. The repository's history is valuable in its own right and it is very important to be able to tell what actually happened. Altering published history is a common source of problems for anyone working on the project.

  • However, there are cases where rewriting history is legitimate. These are when:

    • You are the only one working on the branch and it is not being reviewed.

    • You want to tidy up your branch (eg. squash commits) and/or rebase it onto the "main" in order to merge it later.

    That said, never rewrite the history of the "main" branch or any other special branches (ie. used by production or CI servers).

  • Keep the history clean and simple. Just before you merge your branch:

    1. Make sure it conforms to the style guide and perform any needed actions if it doesn't (squash/reorder commits, reword messages etc.)

    2. Rebase it onto the branch it's going to be merged to:

      [my-branch] $ git fetch
      [my-branch] $ git rebase origin/main
      # then merge
      

      This results in a branch that can be applied directly to the end of the "main" branch and results in a very simple history.

      (Note: This strategy is better suited for projects with short-running branches. Otherwise it might be better to occassionally merge the "main" branch instead of rebasing onto it.)

  • If your branch includes more than one commit, do not merge with a fast-forward:

    # good - ensures that a merge commit is created
    $ git merge --no-ff my-branch
    
    # bad
    $ git merge my-branch
    

Misc.

  • There are various workflows and each one has its strengths and weaknesses. Whether a workflow fits your case, depends on the team, the project and your development procedures.

    That said, it is important to actually choose a workflow and stick with it.

  • Be consistent. This is related to the workflow but also expands to things like commit messages, branch names and tags. Having a consistent style throughout the repository makes it easy to understand what is going on by looking at the log, a commit message etc.

  • Test before you push. Do not push half-done work.

  • Use annotated tags for marking releases or other important points in the history. Prefer lightweight tags for personal use, such as to bookmark commits for future reference.

  • Keep your repositories at a good shape by performing maintenance tasks occasionally:

License

cc license

This work is licensed under a Creative Commons Attribution 4.0 International license.

Credits

Agis Anastasopoulos / @agisanast / http://agis.io ... and contributors!