version-control
Version Control with Git
This skill equips an AI agent to perform the full spectrum of Git-based version control tasks, from initializing a repository and crafting atomic commits to orchestrating branching strategies, resolving merge conflicts, and configuring automation with hooks. It covers both everyday workflows and advanced operations needed for professional team collaboration.
Workflow
-
Assess Repository State: Run
git status,git log --oneline -10, andgit branch -ato understand the current branch, uncommitted changes, recent history, and available remotes. This context determines which operations are safe to perform. -
Stage and Commit Changes: Group related changes into atomic commits. Write commit messages that start with a concise summary line (50 characters or fewer), followed by a blank line and an explanatory body when the change is non-trivial. Follow the project's commit convention (Conventional Commits, Angular style, etc.) if one exists.
-
Branch Management: Create feature, bugfix, or release branches from the appropriate base. Use a consistent naming convention such as
feat/short-description,fix/issue-123, orrelease/1.2.0. Delete stale branches after merging to keep the branch list clean. -
Synchronize with Remote: Fetch and pull regularly to stay up to date. Push feature branches with the
-uflag on first push. Before merging, rebase or merge the base branch into the feature branch to resolve conflicts early in an isolated context. -
Resolve Conflicts: When conflicts arise, inspect the conflicting files, understand both sides of the change, choose the correct resolution (or combine both), mark the file as resolved with
git add, and complete the merge or rebase. Always run tests after resolution to confirm correctness. -
Automate with Hooks and CI: Set up Git hooks (pre-commit for linting/formatting, commit-msg for message validation, pre-push for test runs) and ensure
.gitignorecovers build artifacts, environment files, and OS metadata. Integrate with CI pipelines to enforce quality gates on every push.