RTC Website

A remote Git repository

Your Git project from subsection 0.2.1 exists only on your VM. However, it is usually a good idea to maintain a remote (i.e., cloud) repository. Many excellent services are available for hosting Git repositories.

Setting up a remote Git repository

GitHub

You will need a GitHub account. Sign up for an account here: github.com/join We will interact with GitHub through its command-line interface gh, which has been installed on the VM.

In a Git Bash terminal window, cd to your workspace directory and authorize your GitHub account with

winpty gh auth login -w -p https

Enter Y for “yes” and follow the instructions to authenticate in the web browser. Your GitHub account is now ready to use in the terminal.

Now we would like to add your workspace repository to GitHub. Simply

gh repo create workspace --private --source .

You should see confirmation that the remote repository was created. The last step is to push your local repository up to the remote repository with

git push --set-upstream origin master

Check it out on the web interface—you should see your repository files.

Pushing to and pulling from the remote repository

The remote wrinkle that we’ve added to the Git project need not cause confusion. Interacting with the remote repository is rather straightforward, as outlined in figure C.2. When the local repository has new commits, we can push these to the remote repository with

git push

Likewise, when the remote repository has commits that we would like to pull down to the local repository, use the following:

git pull
 Figure C.2
Figure C.2: The four sections of a Git project with a remote repository and the git commands that move files among them.

Often, more than one local copy of a repository exists. Consider that multiple programmers often work on a single remote repository, each with their own local copy. From time to time, two programmers may edit the same file in their own local repository. Usually, Git will happily merge these changes when you run git pull, but if the same line was edited by two programmers, a merge conflict will occur. Not to worry, though—the process of resolving a merge conflict is rather straightforward (Chacon and Straub 2014, 76).

So far, we have only explored the basics of Git. More advanced topics like forking, and even a few fundamental topics like cloning and branching, have been left for readers to explore on their own.

progit

Chacon, Scott, and Ben Straub. 2014. Pro Git. 2nd ed. USA: Apress. https://git-scm.com/book/en/v2.

Online Resources for Section C.2

No online resources.