Why Git for documentation?
Git provides essential capabilities for managing documentation.- Version history: See what changed, when, and why for every file.
- Collaboration: Multiple people can work on different parts simultaneously.
- Safety: Experiment without breaking live documentation.
- Review workflows: Team members can review changes before publishing.
- Recovery: Undo mistakes or restore previous versions.
New to Git?
If you’re completely new to Git and version control, here’s a path to get started.1
Use the web editor first.
The web editor handles Git operations automatically.
- See any changes visually as you make them.
- Create branches with one click.
- Publish and create pull requests without using Git commands.
2
Learn by doing.
As you use the web editor, you’re using Git.
- Save changes creates a commit.
- Create branch creates a Git branch.
- Publish opens a pull request for review.
3
Explore local development when it is useful.
You can manage your documentation entirely with the web editor and dashboard, but you can customize your workflow by working in your local environment.
- Create and edit files in your favorite editor.
- Use command line Git, GitHub desktop, or an extension in your editor.
- Preview changes locally before publishing.
- Integrate with other tools like support tickets, issue tracking, and design systems.
Core Git concepts
Branch
Branch
A branch points to a specific commit in your repository. Your live documentation builds from a deployment branch. You can have any number of other branches with changes that are not yet published to your live documentation. If you want to incorporate the changes from a branch into your live documentation, you can merge the branch into your deployment branch through a pull request.Use branches to work on changes without affecting your live documentation, safely experiment with new features, and get reviews before publishing.
Clone
Clone
Download a complete copy of a repository to your computer, including all files and full history. When you clone, you get everything needed to work locally.
Commit
Commit
A saved snapshot of your changes at a specific point in time. Each commit includes a message describing what changed and creates a permanent record in your project history.
Conflict
Conflict
Occurs when two people change the same part of a file differently. Git asks you to manually choose which change to keep or combine both changes.
Deployment branch
Deployment branch
The primary branch of your project. Changes to this branch automatically publish to your documentation site. Often called
main, but you can set any branch as your deployment branch.Diff
Diff
A diff (or difference) shows the changes between two versions of a file. When reviewing pull requests, diffs highlight what is different from the original version of the file.
Merge
Merge
Combine changes from one branch into another. Usually done via pull request after review to incorporate feature work into your deployment branch.
Pull
Pull
Get the latest changes from the remote repository to your local copy. Keeps you up to date with other people’s work.
Pull request
Pull request
A way to propose merging your changes on a branch into your live documentation. Allows for review and discussion before changes go live. Commonly called a PR, and also called a merge request in GitLab.
Push
Push
Send your local commits to the remote repository. This makes your changes available to others and can trigger automatic deployments.
Remote
Remote
A version of your repository hosted on a server. Your local repository connects to a remote repository to push and pull changes.
Repository
Repository
Your documentation’s source code with all the files, and their history, that make up the pages of your documentation site. The web editor connects to your documentation repository to access and modify content.
Stage
Stage
Prepare specific changes to include in your next commit. Staging lets you organize changes into logical commits.
How the web editor uses Git
The web editor connects to your Git repository through the GitHub App or GitLab integration and automates common Git operations. When you:- Open a file: The editor fetches the latest version from your repository, ensuring you’re always working with up to date content.
- Make changes: The editor tracks your changes as a draft that can become a commit when you’re ready to save your work.
- Save changes: The editor makes a commit with your changes, preserving your work in the project history.
- Create a branch: The editor creates a new branch in your repository that anyone with access to the repository can use to collaborate and review changes.
- Publish on your deployment branch: The editor commits and pushes directly to your deployment branch, which publishes your changes immediately.
- Publish on other branches: The editor creates a pull request, which allows you to get feedback from others before merging your changes into your deployment branch.
Common workflows
Publish directly to your deployment branch
- Using web editor
- Using local development
- Open file in the web editor.
- Make changes.
- Click Publish.
- Changes appear in the repository and deploy automatically.
Work on a feature branch
- Using web editor
- Using local development
To create pull requests from the web editor, you must have a branch protection rule enabled that requires pull requests before changes can merge into your deployment branch. Without branch protection rules, changes on branches merge to your deployment branch when published.
- Create branch from the branch dropdown in the editor toolbar.
- Make and save changes on the branch.
- Click Publish to create a pull request.
- Merge the pull request when ready.
Review changes before publishing
1
Create a feature branch.
Work on changes in a branch separate from your deployment branch so that you can share and review the changes before publishing.
2
Make your changes.
Edit files and commit changes to the feature branch.
3
Create a pull request.
Create a pull request to propose merging the changes on your feature branch into the deployment branch.
4
Review the diff.
Check your changes. The pull request shows line-by-line differences from the original version of the file.
5
Get team feedback.
Team members can comment on specific lines or overall changes. Make any changes and commit them to the feature branch.
6
Merge when approved.
Merge the pull request to publish changes to your live documentation.
Git best practices
Every team develops their own workflows and preferences, but these are some general best practices to get started.- Write descriptive commit messages: Be specific about what changed using active language.
Fix broken link in API docsis more informative thanupdate page. - Use descriptive branch names: Branch names should explain the purpose the branch. Use informative names like
update-api-referenceinstead of generic names liketempormy-branch. - Keep branches focused: Keep the changes on a branch focused on a specific task or project. This makes reviews easier and reduces conflicts.
- Delete branches after merging: Delete branches when you no longer need them to keep your repository tidy.
- Pull before you push: Always pull the latest changes before pushing to avoid conflicts. The web editor does this automatically.
- Review your own changes first: Check the diff before creating a pull request.