Chapter 3 Beyond the basics

Git verbs in this section
git clone, git remote, git pull, git push, git fetch, ~~git checkout, git branch, git merge~~

In this chapter, we will continue to build up from chapter 2. Most of the workflow will be familiar to us at this point. We will introduce the new concept of working with remote repository.

3.1 Remote Repository

So far, our workflow has revolved around working on our local machine. Git, in addition to being a version tracking tool, is a great collaboration tool as well. To collaborate using git, we make changes on our local machine and then send the changes to a shared remote repository. The workflow is as follows:

  • Download the remote repository into the local machine (multiple ways to do so. Will discuss later)
  • Move inside the directory, make changes, then create commits, etc.
  • Inspect the current status of the repository (includes checking status, commits, logs, remote, diff, etc.)
  • Upload the changes back to the remote repository

3.1.1 Exercise remote repository

  1. Download ie. “Clone” any (try this) remote repository. To do this, we will browse to a remote repository, find the location that says download or clone code. Usually the download icon looks like a little downward arrow. Git Clone

copy the repository link (click on the clipboard icon)

$> git clone <link of remote repository> [<new-nme>]

  1. Open that directory.

  2. Check the remote of that repository. This shows where to download the changes from and the changes to upload to.

$> git remote --verbose

  1. Make changes, add commits

  2. Upload the changes back to the remote source. What happens?

$> git push <origin> <branchname>

3.2 Remote repository continued

Remote repositories can be public or private. Public repositories are the ones where everybody can see the contents and suggest changes. Public repositories are analogous with Open Source Software (not equal). On the other hand, private repositories are only accessible to certain users. Only authenticated users can access private repositories

In the last section, we tried to make changes and push to a git repository that we didn’t have access to. The owner of remote repository has not provided us with direct access. That is why we coud not write to the remote even though we could download the code. Being able to write to remote repository requires access and authentication.

Side Note: We can “recommend” changes to repository that we don’t have write access to by “fork”ing that remote to our account, making changes there and creating a “pull request”. More on this later.

We will need to have an account on the remote repository server such as stash, gitlab, github, sourceforge, etc. After we confirm that we have an account, we need to set up our local computer to talk to the remote server. This can be done in a few ways.

  1. Using ssh keys ??
  2. Using username/password combination
  3. API keys (won’t cover now)

3.2.1 Exercise

  1. Setting up remote repository
  2. Accessing connecting local machine with remote repository
  3. Debugging session

3.3 Shared Remote

Very often teams and organizations have shared remote repositories and the members of such groups can have access to make changes on those repositories directly. Members can create new sub-directories, files, commits, and branches and apply those changes on remote repositories as well.

General workflow with shared repositories but necessarily git specific.

  • creating a branch on remote and pulling that down
  • pushing change to a branch (not default)
  • pull request and code review

3.3.1 Exercise

Explore shared remote repository. Look at current branches, code, etc.

3.4 Conclusion

In this chapter we covered working with remote repositories such as pulling and pushing changes between local and remote. We also set up our local machine to communicate with remote server (if we covered setting up ssh, mention here).

At this point we should be able to work with git in a professional setting. There is much more to learn. In future topic, we will discuss issues we face during working with git such as merge conflicts, tracking certain files, etc.