Git Version Control
Git is a distributed version control system in which every clone is a complete repository; commits, branches, and history are all handled locally, and networking occurs only on push and pull. In AI projects it is not just a code keeper but infrastructure for experiment management, multi-person collaboration, and online rollback, and whether it is used correctly directly determines whether the team's rhythm is smooth.
Core Principles
Git stores version history as a series of commit objects; each commit records a complete directory snapshot and points to its parent commit, ultimately forming a directed acyclic graph. A branch is essentially just a movable pointer to a certain commit, so creating and switching branches costs almost nothing, which is the fundamental difference between Git and older generations of centralized version control. Once you truly understand that "a branch is a pointer," you will no longer be afraid of branch operations.
The three-part structure of working directory, staging area, and local repository is equally critical. Changes first enter the working directory, enter the staging area after add, and are written into history only after commit. The existence of the staging area lets people carefully select what to commit and split a change mixing several purposes into several semantically clear commits. Whether history is clean often depends on whether the staging area is used well.
A remote is essentially another repository plus a set of reference tracking mechanisms, with local and remote branches linked through tracking relationships. So-called pushing means transferring local commit objects to the remote and moving the remote branch pointer; conflicts arise because both sides modified the same content in similar places, and Git cannot make a semantic judgment on people's behalf.
Key Points
First, the branching model must match team size. Small teams are best served by trunk development plus short-lived feature branches, ideally lasting no more than a few days; medium and large teams commonly use Git Flow or a GitLab Flow-like model, requiring release branches and hotfix branches. Whichever is used, the principle is the same: the longer a branch lives, the heavier the merge conflicts. AI projects should also give experimental code a separate repository to avoid experimental changes polluting the main repository's history.
Second, the choice between rebase and merge must be made according to the occasion. For commits on a personal branch that have not been pushed, use rebase to organize them into a linear, clean history; for branches already pushed and shared by several people, use merge to preserve the real merge trajectory, and strictly forbid rebase, otherwise it will make others' local history diverge from the remote and force a hard push to redo. The only criterion is: is this history private or shared?
Third, conflict handling must reach the semantic level. Tools only mark conflict blocks, and the real judgment is "what are the intentions of the two sides, and which one should be kept in business terms." When handling, first understand where both sides' changes come from, communicate with the other party when necessary, and be sure to run tests locally before committing after resolution. Treating a conflict as a disaster and blindly choosing ours is the starting point of more than one online incident. At the same time, make good use of git stash and cherry-pick to handle temporary branch switching and hotfixes.
Fourth, .gitignore must ignore large model files. Weights, datasets, checkpoints, and exported onnx files are often several GB, and once committed they remain in history permanently, bloating the repository until it is hard to clone. Ignore rules must be written at project initialization, covering common model formats and data directories. If something has already been committed by mistake, tools like filter-repo are needed to rewrite history and force push, and all collaborators must be notified to re-clone, at great cost. In addition, Git LFS can be used to manage large files that truly need versioning, but with an awareness of quota.
Fifth, standardize commit messages, protect the main branch, and run hook checks before committing. Commit messages should state "why the change" rather than "what changed," because what changed can be seen from the diff.
Common Misconceptions
Misconception one: treating rebase as a universal tidying tool and using it indiscriminately on pushed branches. Misconception two: mechanically keeping one's own version during conflicts and losing a colleague's fix. Misconception three: stuffing data and weights into the repository, or committing first and adding ignore later, causing history to bloat permanently.
Application Scenarios
Branch management for model training experiments, multi-person code review, rapid rollback of online incidents, version tracking of configuration and scripts, contribution workflows for open-source projects, and tagging release versions.