GitHub Desktop tracks all changes to all files as you edit them. You can decide how to group the changes to create meaningful commits.
Similar to "saving" a file, a commit is a change to one or more files in your branch. Git assigns each commit a unique ID (the "SHA" or "hash") that tracks:
- The specific changes
- When the changes were made
- Who created the changes
When you make a commit, you include a commit message that briefly describes the changes. You can also add a co-author on any commits you collaborate on.
1. Choosing a branch and making changes
- Create a new branch, or select an existing branch by clicking Current Branch on the toolbar and selecting the branch from the list.
- Using your favorite text editor, such as Atom, make the necessary changes to files in your project.
2. Selecting changes to include in a commit
As you make changes to files in your text editor and save them locally, you also see the changes in GitHub Desktop.
- The red icon indicates removed files.
- The yellow icon indicates modified files.
- The green icon indicates added files.
- To add all changes in all files to a single commit, keep the checkbox at the top of the list selected.
- To add all changes in one or more files to a single commit, deselect the files you don't want included, leaving only the files you want in the commit.
Creating a partial commit
If one file contains multiple changes, but you only want some of those changes to be included in a commit, you can create a partial commit. The rest of your changes will remain intact, so that you can make additional modifications and commits. This allows you to make separate, meaningful commits, such as keeping line break changes in a commit separate from code or prose changes.
When you review the diff of the file, the lines that will be included in the commit are highlighted in blue. To exclude the change, click the changed line so the blue disappears.
You can discard all the uncommitted changes in one file, or discard all changes in all files since the last commit.
- In the list of changed files, right click (or
control+ click) on the file you want to discard the changes since the last commit.
- Click Discard Changes to discard changes to that file, or Discard All Changes to discard changes to all files since the last commit.
- In the confirmation dialog, review the files affected and click Discard Changes.
Tip: The changes you discarded are saved in a dated file in the Trash and you can recover them until the Trash is emptied.
- In the list of changed files, right click on the file you want to discard changes to.
- Click Discard changes to discard changes to that file, or Discard all changes to discard changes to all files since the last commit.
- In the confirmation dialog, review the files affected and click Discard changes.
Tip: The changes you discarded are saved in a file in the Recycle Bin and you can recover them until it is emptied.
3. Write a commit message and push your changes
Once you're satisfied with the changes you've chosen to include in your commit, write your commit message and push your changes. If you've collaborated on a commit, you can also attribute a commit to more than one author.
At the bottom of the list of changes, in the Summary field, type a short, meaningful commit message. Optionally, you can add more information about the change in the Description field.
- Optionally, to attribute a commit to another author, click the add co-authors button and type the username(s) you want to include.
Under the Description field, click Commit to BRANCH.
- When you're ready to push your commits to the remote repository, on the upper-right side of the toolbar, click Push origin.