Github for mac

From Digital Scholarship Group
Jump to navigation Jump to search

About GitHub

GitHub is a distributed version control system (DVCS) that utilizes a user-friendly website and app and allows multiple users to create, modify, and store coded data and other files within a shared repository. What makes GitHub different from other version control systems is its distributed structure. This means that all files stored in a project repository are saved locally on all platforms being used to work on a project, allowing for greater protection against loss of project data.

Although Git repositories can be managed using the command line, the GitHub web interface and app can expedite the process for those less familiar with command line operations as it takes less time to learn. Once you have signed up for an account with GitHub and have downloaded the app, you can quickly begin interacting with your projects shared repository.

GitHub also adds and element of social networking to version control and project management. Users can be added to organizations and teams, issues can be raised, and each repository has its own associated wiki.

Download, Install, and Set Up

  1. To download GitHub for Mac, please visit http://mac.github.com/.
  2. Once your download is complete, open the file and follow the instructions in the installation window.
  3. Launch GitHub and click “Continue”. Then enter your user info for your GitHub account and click “Continue".
    • NOTE: If you do not already have a GitHub account, please visit https://github.com/ and sign up for a free account.
  4. You will be asked to add any local repositories to the app. You may add any of local repositories you have at this time. If this is your first time using GitHub, you should have no local repositories. To access the repository for your project, you will need to clone it first.

Cloning Repositories

While GitHub supports the creation of repositories by independent users, projects receiving support for GitHub services from the DSG will be provided with a repository that is housed within the DSG’s organization account. The DSG and designated administrators for projects will handle issues regarding read and write permissions for the repositories, allowing you to focus on your research efforts.

However, to be able to share your work with others involved in your project via GitHub, you will first have to clone the repository to your own machine. Fortunately, the process fairly simple:

  1. Open GitHub and click the “+” button in the top left corner.
  2. Switch to the “Clone” tab in the dropdown menu.
  3. Locate the repository you wish to clone. If you have already been given read and write access, the repository should appear under the DSG header.
  4. Select the repository and click the “Clone [repository name]” button.
  5. Select the location and create the directory on your computer where you want the repository and its contents to be saved and click the “Clone” button.
  6. The repository will now be visible in the sidebar of GitHub. When you first clone the repository, there will be no files listed under the “Select All” checkbox. Once you begin modifying files, they will show up here.

Making Changes, Adding, and Deleting Files

New files and changes to existing files are made in your file editor of choice, not directly in GitHub, but it is useful to know how these files will appear in the GitHub interface prior to syncing them to your project’s repository and how the app can be used to expedite the process of editing.

Access Local Copy of Repository

To quickly access your local copy of the repository, control-click the repository’s name in the sidebar and then click “Open in Finder.” This will open a Finder window displaying all the files contained in the repository, which you can then open and edit as needed. This will also be the folder where you’ll save or copy any new files you want to add to the repository.

Adding a New File

When you add a file to the local directory that houses your project’s repository, GitHub recognizes this new file and adds it to the list of files under the heading “Uncommitted Changes” which is located on the “Changes” tab. The green “New” box next to the file name helps you identify these files more quickly.

Making a Change to a File

Once you make a change to a file in your file editor and save it to your local directory, GitHub recognizes that the file has been modified and adds it to the list of files under the heading “Uncommitted Changes” which is located on the “Changes” tab. Unlike new files, there will be no colored box next to the name of a modified file.

Deleting a File

In the event that you want to delete a file from the repository, all you have to do is delete the file from your local directory. The deleted file will then be listed under the “Uncommitted Changes” header on the “Changes” tab just like new and modified files, except it will have a red “Deleted” box next to the file name.

If you do not make any changes to the files in your local directory, these files will not show up in the list. Once you have made all the necessary changes, it is time to commit your changes and sync them to the repository.

Committing and Syncing

The changes you make to your local version of the repository do not appear in the central version on GitHub until you have committed and synced them. As you will notice in the “Uncommitted Changes” list, there are checkboxes beside each file name. Before you commit and sync your changes and make them accessible to others working on your project, make sure that only the changes you want added at that time are checked. Once you have done that, you can either choose the two-click (default) or one-click method for committing and syncing.

Two-Click Method (Default)

  1. Check to make sure the files you want to commit have been checked off on the “Uncommitted Changes” list.
  2. Enter a name and description for your commit. The name is required and GitHub will stop you if you forget to add one. The description is optional.
  3. Click the “Commit” button next to the commit name. The new commit will then appear under the “Unsynced Commits” header.
    • NOTE: If you have made a mistake in your commit, click the “Edit” button beside that commit to revert to the previous steps.
  4. Click the “Sync” button in the top right of the app window.

One-Click Method

  1. Check to make sure the files you want to commit have been checked off on the “Uncommitted Changes” list.
  2. Enter a name and description for your commit. The name is required and GitHub will stop you if you forget to add one. The description is optional.
  3. Click the toggle button next to the “Commit” button. This will change the “Commit” button to “Commit and Sync.”
    • NOTE: You will only have to do this once, as it becomes the default when you open your GitHub app. Undo this at any time by pressing the toggle button again.
  4. Click the “Commit and Sync” button.

Whichever method you choose depends on how you prefer to work and is entirely up to you. The one-click method is faster but the two-click method gives you the option to edit a commit before syncing if you have made a mistake.

Branching and Merging

Adding Branches

Branches are useful when you want to explore new ideas for your project without altering the primary version of your repository, called the “master branch” by default. Branching is very easy to do in GitHub, and there are two different options for creating a new branch.

Option 1

  1. Click the add branch button located in the top bar to the left of the name of the branch in which you are currently working.
  2. In the box that appears, type the desired name for your new branch and select the existing branch you wish to branch from.
  3. Click the “Create Branch” button.
  4. To begin working in this branch, click the name of your current branch in the top bar and select the new branch from the drop down menu.

Option 2

  1. Click on the Branches tab.
  2. Click on the “+” button to the right on the existing branch from which you wish to create the new branch.
  3. In the box that appears, type the desired name of your new branch.
  4. Click the “Branch” button.

Merging Branches

Once you have finished working on the branch you created and are happy with the changes you have made, you can then merge the branch back into the master branch. To do this, follow the steps below:

  1. Click on the Branches tab.
  2. Click the “Merge View” button in the top right corner.
  3. Drag the branch you have been working on into the first box and drag the branch you wish to merge it with into the second box.
    • NOTE: To drag a branch, click and hold the dots on the left of the branch name.
  4. Click the “Merge Branches” button.

Deleting Branches

By default, branches that you merge will remain in the repository, but you can delete them if you no longer have a use for them. To do this, follow the steps below:

  1. Click on the Branches tab.
  2. Click the arrow button to the right on the branch you wish you wish to delete.
  3. Select “Delete” from the drop down menu and then click “Delete” again on the message that appears.

Reviewing History

You can review a list of past commits by clicking on the “History” tab at the top of the app window. Clicking on a commit in the list will allow you to see what changes were made to any files during that particular commit.

The commit history is also the location in GitHub where you can undo a commit you or someone else made previously. To do so, click on the commit you want to undo, then click the cog icon, then click “Revert this Commit”, and then click “Sync”. A similar action can also be taken if you click “Roll Back to this Commit” after clicking the cog icon.