COURSE 3 – INTRODUCTION TO GIT AND GITHUB

Module 3: Working with Remotes

GOOGLE IT AUTOMATION WITH PYTHON PROFESSIONAL CERTIFICATE

Complete Coursera Study Guide

Last updated:

INTRODUCTION – Working with Remotes

In this module, you’ll be introduced to GitHub and learn how it works with Git. You’ll create new repositories and clone those repositories onto your computer. Next, we’ll explain what a remote repository is, how we can work with them, and how we can host them. You’ll get familiar with commands like modify, stage, and commit, which will be used for local changes, as well as the fetch command, which can pull any changes from remote repositories.

We’ll cover secure shell protocol and when to use API keys. Our final lesson will focus on learning about conflicts. This will allow you to explore the concepts of pull-merge-push workflows, pushing remote branches and rebasing your changes.

Learning Objectives

  • Describe the advantages of using separate branches
  • Utilize the git rebase command
  • Describe what GitHub is and how to interact with it
  • Explain what a remote repository is
  • Utilize remote repositories, fetch new changes, and update local repositories
  • Utilize the pull-merge-push workflow to address conflicts
  • Push remote branches so code can be viewed and tested by collaborators
  • Explain what rebasing is

PRACTICE QUIZ: INTRODUCTION TO GITHUB

1. When we want to update our local repository to reflect changes made in the remote repository, which command would we use?

  • git clone <URL>
  • git push
  • git pull (CORRECT)
  • git commit -a -m

Right on! git pull updates the local repository by applying changes made in the remote repository.

2. git config –global credential.helper cache allows us to configure the credential helper, which is used for …what?

Right on! git pull updates the local repository by applying changes made in the remote repository.

2. git config –global credential.helper cache allows us to configure the credential helper, which is used for …what?

  • Troubleshooting the login process
  • Dynamically suggesting commit messages
  • Allowing configuration of automatic repository pulling
  • Allowing automated login to GitHub (CORRECT)

Nice work! By configuring the credential helper, we can avoid having to type in our username and password repeatedly.

3. Name two ways to avoid having to enter our password when retrieving and when pushing changes to the repo. (Check all that apply)

  • Implement a post-receive hook
  • Use a credential helper (CORRECT)
  • Create an SSH key-pair (CORRECT)
  • Use the git commit -a -m command.

Awesome! The credential helper caches our credentials for a time window, so that we don’t need to enter our password with every interaction.

Great job! We can create an SSH key-pair and store the public key in our profile, so that GitHub recognizes our computer.

4. Name the command that gathers all the snapshots we’ve taken and sends them to the remote repository.

  • git commit -a -m
  • git push (CORRECT)
  • git pull 
  • git clone <URL>

Excellent! git push is used to update the remote repository with our local changes.

5. Which BEST describes GitHub?

  • A distributed Version Control System (VCS)
  • A Software Configuration Management system (SCM)
  • A remote repository hosting service for Git (CORRECT)
  • A wiki site for Git users

Nice job! GitHub provides free access to a Git server for public and private repositories

6. After making changes to our local repository, how do we update the remote repository to reflect our changes?

  • Use the git clone command to clone the repository to the server.
  • Use the git push command to send snapshots to the remote repository. (CORRECT)
  • Upload a README.md file with Markdown.
  • Use the Create a repository form on the website

Awesome! The git push command gathers all the snapshots we’ve taken and sends them to the remote repository.

PRACTICE QUIZ: USING A REMOTE REPOSITORY

1. In order to get the contents of a remote branch without automatically merging, which of these commands should we use?

  • git pull
  • git remote update (CORRECT)
  • git checkout
  • git log -p -1

You got it! git remote update will fetch the contents of all remote branches and allow us to merge the contents ourselves.

2. If we need to find more information about a remote branch, which command will help us?

  • git fetch
  • git checkout
  • git remote update
  • git remote show origin (CORRECT)

Right on! If you want to see more information about a particular remote branch, you can use the git remote show command. Don’t forget the commit ID!

3. What command will download remote branches from remote repositories without merging the content with your current workspace automatically?

  • git checkout
  • git pull
  • git fetch (CORRECT)
  • git remote update

Nice work! git fetch will download remote updates, such as objects and refs, from the remote branch.

4. What type of merge creates a new merge commit?

  • Fast-forward merge
  • Implicit merge
  • Explicit merge (CORRECT)
  • Squash on merge

Woohoo! An explicit merge creates a new merge commit. This alters the commit history and explicitly shows where a merge was executed.

5. What method of getting remote contents will automatically merge the remote branch with the current local branch?

  • git fetch
  • git checkout
  • git remote update
  • git pull (CORRECT)

Great job! git pull automatically merges the remote branch with the current branch.

6. If we want to make a change to a remote branch, what must we do?

  • Directly make the change
  • Use the git branch -r command
  • Pull the remote branch, merge it with the local branch, then push it back to its origin. (CORRECT)
  • Use the git remote -v command

Excellent! We still have to go through the normal workflow to change remote branches.

7. What’s the main difference between git fetch and git pull?

  • git fetch fetches remote updates but doesn’t merge; git pull fetches remote updates and merges. (CORRECT)
  • git pull fetches remote updates but doesn’t merge, while git fetch does.
  • git fetch clones the entire repository.
  • git pull requires a password while git fetch doesn’t.

Nice job! git pull instantly merges while git fetch only retrieves remote updates.

8. Assuming no merge conflicts, which type of merge does git pull perform automatically?

  • Three-way merge
  • Explicit merge
  • Fast-forward merge (CORRECT)
  • Half-merge

Awesome! As long as there are no conflicts, Git will move the current branch tip up to the target branch tip and combine histories of both commits.

PRACTICE QUIZ: SOLVING CONFLICTS

1. If you’re making changes to a local branch while another user has also made changes to the remote branch, which command will trigger a merge?

  • git push
  • git pull (CORRECT)
  • git rebase
  • git fetch

Nice job! The git pull command runs git fetch with the given parameters, then calls git merge to merge the retrieved branch heads into the current branch.

2. Which of the following is a reason to use rebase instead of merging? 

  • When you want to keep a linear commit history (CORRECT)
  • When you want a set of commits to be clearly grouped together in history
  • When you are on a public branch
  • When pushing commits to a remote branch

Way to go! git rebase is useful for maintaining a clean, linear commit history.

3. Where should we keep the latest stable version of the project?

  • The master branch
  • A separate branch from the master branch (CORRECT)
  • The debug branch
  • A remote branch

Correct

4. Which of the following statements represent best practices for collaboration? (check all that apply)

  • When working on a big change, it makes sense to have a separate feature branch. (CORRECT)
  • You should always rebase changes that have been pushed to remote repos.
  • Always synchronize your branches before starting any work on your own. (CORRECT)
  • Avoid having very large changes that modify a lot of different things. (CORRECT)

Right on! This lets you work on new changes, while still enabling you to fix bugs in the other branch.

Awesome! That way, whenever you start changing code, you know that you’re starting from the most recent version, and you minimize the chances of conflicts or the need for rebasing.

Woohoo! Instead, try to make changes as small as possible, as long as they’re self-contained.

5. What command would we use to change the base of the current branch?

  • git checkout <branchname>
  • git pull
  • git rebase <branchname>  (CORRECT)
  • git fetch

Right on! You can also use git rebase <branchname> to change the base of the current branch to be <branchname>.

6. What should you do with the <<<<<<<, =======, and >>>>>>> conflict markers when resolving a merge conflict?

  • Remove all of the conflict markers and only leave the code as it should be after the merge. (CORRECT)
  • Leave the conflict markers surrounding the code that you want to keep.
  • Remove the <<<<<<< and >>>>>>> markers, and put the ======= marker in front of the lines that you want to keep.
  • Do nothing.

Awesome! Conflict markers aren’t required when resolving a merge conflict.

7. How do you switch to a new local branch?

  • git checkout -b <branch name> (CORRECT)
  • git branch b
  • git pull origin branch
  • git merge branch

Great job! The command git checkout -b <branch name> will first create a new branch and then switch to it.

8. What does “git rebase refactor” do?

  • Move the current branch on top of the refactor branch (CORRECT)
  • Move the refactor branch on top of the current branch
  • Move the refactor branch on top of the master branch
  • Move the master branch on top of the refactor branch

Nailed it! This makes debugging easier and prevents three-way merges by transferring the completed work from one branch to another.

9. Generally, git rebase is an alternative to which command?

  • git fetch
  • git merge (CORRECT)
  • git push
  • git pull

Awesome! Rebasing instead of merging rewrites history and maintains linearity, making for cleaner code.

10. Which of the following statements is true regarding best practices for collaboration?

  • Keep the stable version of the project in the master branch, and the latest version on a separate branch.
  • Try to fit all changes into one large change.
  • You should always rebase changes that have been pushed to a remote repo.
  • Always synchronize your branches before starting any work on your own. (CORRECT)

Excellent! This way, when you start changing code, you’re starting from the most recent version, minimizing chances of conflicts or the need for rebasing.

INTRODUCTION TO GITHUB

1. Which of the following files/folders are automatically created after initializing a new Git repository?

  • codespace
  • README.md
  • .git folder (CORRECT)
  • git operations

Correct

2. If you create a private repository on Github, what will you need to clone the repo via HTTPS?

  • Your Github username and your password
  • Your Github password and your personal access token 
  • Your Github username and your personal access token (CORRECT)
  • Your Github username and an asynchronous password

Correct

3. What happens when the git clone command is used? Select all that apply. 

  • It initializes a .git directory. (CORRECT)
  • It creates a new directory with the same name as the repository. (CORRECT)
  • It pulls the latest changes from the remote repository
  • It creates a working copy of the latest version. (CORRECT)

Correct

4. What is the command to add content from the working directory into the staging area for the next commit? 

  • nano README.md
  • git add (CORRECT)
  • git status
  • git clone [URL]

Correct

5. When are you required to enter a commit message? 

  • Every time you commit changes. (CORRECT)
  • Only when you permit another user to commit to your repository.
  • Every time you log out of Github.
  • When you commit to another user’s repository.

Correct

6. What does the command git commit do? Select all that apply.

  • It adds content from the working directory into the staging area.
  • It stores the commit message for this new commit. (CORRECT)
  • It captures a snapshot of the project’s currently staged changes. (CORRECT)
  • It stores the current contents of the index in a new commit. (CORRECT)

Correct

7. You have added files on a remote repository, which aren’t yet present on your local repository. You need to fetch and download content from the remote repository and update the local repository to match that content. What is the command you will use?

  • git commit
  • git pull origin main (CORRECT)
  • git add README.md
  • git push origin main

Correct

8. Recently, you added files on a remote repository, but those files aren’t yet present on your local repository. What will happen if you try to push something from the local repository to the remote repository? 

  • Your local repository will automatically overwrite your remote repository. 
  • Your remote repository will automatically overwrite your local repository. 
  • Your local repository will create another remote repository. 
  • Your attempt will return an error. (CORRECT)

Correct

9. What command is used to push changes from the local repository to the remote repository? 

  • git agree origin main
  • git push origin main (CORRECT)
  • git pull origin main
  • git update origin main

Correct

10. How can you create a Personal Access Token? 

  • In the settings for your local repository
  • In the Developer settings of your Github account (CORRECT)
  • In the directory of your repository
  • In the settings of your remote repository

Correct

11. What does the command git add do? 

  • Saves all changes.
  • Pushes additional commits to the main branch
  • Adds content from a local repository to a remote repository.
  • Adds content from the working directory into the staging area for the next commit (CORRECT)

Correct

12. What will the command git status show? 

  • The status of files in your working directory but not your staging area
  • The status of files in your staging area but not your working directory
  • The different states of files in your working directory and staging area
  • Only the status of files that are staged but not yet committed (CORRECT)

Correct

13. Every commit has an associated commit message. What is a commit message?

  • A log message from the local repository that is pushed to the remote repository
  • A log message from the system recording the username and time
  • A log message for the local repository that is pulled from the remote repository
  • A log message from the user describing the changes (CORRECT)

Correct

14. Every commit has an associated commit message from the user describing the changes. What must you include in a commit message? 

  • The date and time of the commit
  • There are no specific requirements for a commit message. (CORRECT)
  • The username and personal access token 
  • The username and the repository of the commit

Correct

15. Recently, you added files to a remote repository, but not the local repository. Now you want to push changes from the local repository to the remote one. What do you need to do?

  • Push the log files from the local repository into the remote repository, update the remote repository log, then push the changes from the local repository to the remote one. 
  • Pull the log files from the remote repository into the local repository, update the local repository log, then push the changes from the local repository to the remote one. 
  • Push the current snapshot/commit in the local repository to the remote repository, update the remote repository from the local repository, then push the changes from the remote repository to the local one. 
  • Pull the current snapshot/commit in the remote repository to the local repository, update the local repository from the remote repository, then push the changes from the local repository to the remote one. (CORRECT)

Correct

16. When creating a new repository on Github, what will selecting private repository access allow others to do?

  • Choosing private means no one but you can see or commit to the repository. 
  • Choosing private means you choose who can see and commit to the repository. (CORRECT)
  • Choosing private allows only people with a Github account to see and commit to the repository. 
  • Choosing private allows anyone to see the repository, but no one but you can ever commit to it.

Correct

17. Which of the following commands will clone a repository named ‘project’ from a remote server named ‘server’.?

  • git clone project@server
  • git clone server/project (CORRECT)
  • git project clone server
  • git clone project server

Correct

18. After you have committed changes, you can push the committed changes from your local repository to a remote repository on the main branch by using which of the following commands? 

  • git commit
  • git push origin main (CORRECT)
  • git add example.py
  • git add README.md

Correct

19. What command is used to clone a Git repository onto your local machine?

  • git copy
  • git pull
  • git clone (CORRECT)
  • git download

Correct

20. What is the command to add content from the working directory into the staging area for the next commit? 

  • git status
  • nano README.md
  • git clone [URL] 
  • git add (CORRECT)

Correct

21. Git uses the term “commit”. In more common terms, how would you describe a commit?

  • Git commit is like making a copy of your work.
  • Git commit is like getting a sharing link to your work.
  • Git commit is like saving your work. (CORRECT)
  • Git commit is like adding security to your work.

Correct

22. After you set a Github username, any future commits you push to GitHub from the command line will be represented by this name. What happens if you change the name associated with your Git commits?

  • This will only affect future commits and won’t change the name used for past commits. (CORRECT)
  • This will affect future commits and change the name for past commits that you pushed to GitHub from the command line. 
  • This will affect future commits and automatically change the name for past commits. 
  • This will affect future commits, but you can change the name for past commits using git config.

Correct

23. Which of the following commands will create a snapshot of the current state of the repository in Git?

  • git clone
  • git pull
  • git commit (CORRECT)
  • git push

Correct

24. What is the git pull command used for? 

  • To pull the current snapshot/commit in the remote repository to the local repository.
  • To clone content from one remote repository and update another remote repository to match that content.
  • To fetch and download content from a local repository and update the remote repository to match that content.
  • To fetch and download content from a remote repository and update the local repository to match that content. (CORRECT)

Correct

25. After you create a remote repository, you need to create a local copy of this remote repository on your machine. What is the syntax for this process?

  • cd directory_name
  • git clone [URL] directory_name
  • You can do this only from the Github website.
  • git clone [URL] (CORRECT)

Correct

26. Recently, you added files to a remote repository, but not the local repository. Now you want to pull these changes from the remote repository to the local one. What command do you use to pull the current snapshot/commit in the remote repository to the local repository? 

  • git update origin main
  • git agree origin main
  • git push origin main
  • git pull origin main (CORRECT)

Correct

CONCLUSION – Working with Remotes

In conclusion, this module has served as a comprehensive introduction to the integration of GitHub with Git, equipping you with essential skills and knowledge to enhance your version control capabilities. Through hands-on activities, you have learned to create new repositories and efficiently clone them onto your local computer. The exploration of remote repositories has provided valuable insights into their functionality, working mechanisms, and hosting considerations.

Acquiring familiarity with fundamental commands like modify, stage, and commit has empowered you to manage local changes effectively. The addition of the fetch command has expanded your toolkit, enabling the retrieval of changes from remote repositories. The module has also addressed crucial aspects such as the secure shell protocol and the appropriate use of API keys, ensuring a secure and informed approach to version control.

The concluding lesson focused on conflicts, offering a deep dive into pull-merge-push workflows. This final section has equipped you with the skills to navigate and resolve conflicts, covering key aspects like pushing remote branches and understanding the intricacies of rebasing your changes. Overall, this module has provided a solid foundation for leveraging GitHub and Git collaboratively, enhancing your proficiency in version control for your coding projects.