Add a Markdown file to a GitHub repository
Markdown is a lightweight markup language that works well for docs-as-code workflows. You can use a GitHub repository to store your Markdown files (.md), then use git and Github for version control. This enables you to work simultaneously with other writers, while ensuring that you are not overwriting each other’s content.
View this article to learn how to add your Markdown file to a GitHub repository.
Prerequisites
Before reading this article, you must have the following:
- A GitHub account
- Access to the GitHub repository used to manage and publish your documentation
- An SSH key added to your SSH agent (see Generating a new SSH key and adding it to the ssh-agent)
- A preferred terminal (such as iTerm2 or Ghostty)
- Git installed to use developer tools
- A preferred integrated development environment (IDE) (such as Visual Studio Code or Cursor)
- A Markdown file
On this page
- Step 1. Clone a GitHub repository
- Step 2. Create a branch to add your Markdown file
- Step 3. Create and merge your pull request in GitHub
Step 1. Clone a GitHub repository
First, you must clone the GitHub repository and place it in a folder on your desktop. It is recommended to place the cloned repository in your Documents folder, as described in the following steps:
- Open your preferred terminal.
-
Change the directory to your
Documentsfolder:cd Documents/ -
Clone the repository:
git clone GITHUB_URLNote: Replace
GITHUB_URLwith the link you copied from your GitHub repository. For example:git clone git@github.com:org/microservices-repo.git. See Cloning a repository for more information.
A message appears in your terminal to indicate when cloning is complete.
Step 2. Create a branch to add your Markdown file
Now that your GitHub repository is cloned, you can add your Markdown file to the repository using git. Complete the following steps:
- Open your preferred terminal.
-
Change the directory to the location of your cloned repository:
cd Documents/REPOSITORY_NAMENote: Replace
REPOSITORY_NAMEwith the name of the cloned folder in Step 1. For example:cd Documents/microservices-repo -
Locate the main branch in the repository:
git checkout main -
Pull down all updates since you were last in the folder:
git pullThe command line interface (CLI) in the terminal shows which changes were made since you were last in the folder, or shows that your local version of the repository is already up to date.
-
Create a new branch:
git checkout -b BRANCH_NAMENote: Replace
BRANCH_NAMEwith a unique name (without spacing) for this change. For example:git checkout -b cbrown/update-articlex - Open your IDE and switch to your local branch. For example, see Switch between branches if you’re using Visual Studio Code.
- Drag and drop your Markdown file to your
/docsfolder. -
Return to your terminal and add the changes to your local branch:
git add .Note: No messages appear in the command line interface after you press Enter.
-
Add a description to the change you’re about to make:
git commit -m "COMMIT_MESSAGE"Note: Replace
COMMIT_MESSAGEwith your description of the change. For example:git commit -m "Add updates to article X" -
Push the changes to the remote branch in GitHub:
git push origin BRANCH_NAMENote: Replace
BRANCH_NAMEwith the same name associated with this change. For example:git push origin cbrown/update-articlex
Your changes are pushed to the remote branch and a GitHub link appears in your terminal.
Step 3. Create and merge your pull request in GitHub
Now that you created the remote branch, you must create a pull request for your teammates to review the changes. After your pull request is approved, you can merge your branch into the main branch. Complete the following steps in GitHub:
- Copy the URL that appears in your terminal and paste it in your web browser. This is your pull request in GitHub.
- Click Create Pull Request.
- (Optional) Click the following tabs to view more about the pull request:
- Commits—See which changes are being merged in this branch.
- Files Changed—See the exact files that were changed.
- Click Merge pull request.
- Click Confirm merge.
Your new article now appears in the GitHub repository.
Next steps
- See Verify the article to confirm that it appears in your documentation set.
- View Troubleshooting commits for common commit issues.