During this module, you will not only get introduced to GitHub but also become familiar with how GitHub integrates with Git. Creating and cloning repositories is part of the process, including learning about remote repositories-how to work with them and where to house them. To manage local change sets, major Git commands such as modify, stage, and commit, are discussed, whereas the fetch command help is utilized to fetch retrieved updates from within the remote repositories.
We will also delve into Secure Shell (SSH) protocol, and you will understand when it is ideal to use API keys when accessing security. The final section will involve conflict management and acquiring proficiency in the pull-merge-push workflow, including also pushing remote branches and rebasing your changes.
The Objectives of Learning are:
Knowledge of the role of distinct branches to be used in Git.
Understanding the git rebase command.
Introduction to what GitHub is and how to use it.
Explaining remote repository and how to work well with it.
An outline for fetching changes from remote repositories to local repos.
The use of pull-merge-push workflow in conflict resolution.
Providing a ground for collaborators and testers to push a common branch.
Understand and apply the concept of rebasing.
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! Right, that’s what! Performing a pull of a git update establishes an update from your local to the remote repository with the incoming alteration, distinctly brings the external merging into the current branch automatically.
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! “Absolutely! One very big advantage” Set up Git for Windows’ “Credential Manager” to avoid typing in a password and username as Git communications with an external remote stack. Git would know how to use your authentication credentials (user name, password, or personal access token) for all future actions once the helper had safely saved them.
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.
The credential helper is just for temporary storage of our credentials; this is so that we don’t have to reenter our password every time we make a new approach.
Good work! This essentially helps in the generation of an SSH key pair, which can be added as a public key in our profile, enabling GitHub to recognize our machine.
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! Use the git push command to upload the changes you have made to the remote repository.
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 gives everyone free access to a Git server, both 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! When the remote repository is used and the push is issued, it will send all of the created snap shots into the URL of the 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! When issued, the git remote update command makes a complete scan through all remote branches, picking up the changes for our manual merge.
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! In order to see more information about any remote branch, make use of the git remote show command. Make sure you include 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! Executing the command git fetch downloads objects and references from the remote branch, which are the newest since the previous fetch-no changes are made to the current workspace.
4. What type of merge creates a new merge commit?
Fast-forward merge
Implicit merge
Explicit merge (CORRECT)
Squash on merge
Woohoo! A deliberate merging produces a new merge commit, which will alter the history of the commits and shows clearly where that merges was performed.
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! Its the command for the git pull, which fetches automatically the updates from the remote branch and then merges them in 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! He can automatically move along relevant information and combine the two commits histories when he can see no conflicts, moving the current branch tip forward to the target branch tip.
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! It is important to understand that the git pull command first executes a git fetch with the respective parameters, then runs a git merge, merging the branch heads fetched with 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! The git reset soft method has the ability to return to a specific version in a linear fashion and then make new commits.
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)
Very much agreed indeed, as this means new features can be worked on as bugs get sorted out in their own branches.
Nice job! You start from the latest code to cause fewer conflicts and fewer rebasing.
Great effort! Keep the changes to the greatest possible diminution so that they are 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! Issuing the git checkout -b command <new branch name> to create a new branch will switch to it and take effect right away.
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! It makes debugging easier and prevents three-way merges by moving finished work from one branch into the next.
9. Generally, git rebase is an alternative to which command?
git fetch
git merge (CORRECT)
git push
git pull
Awesome! Rebasing very much belongs to history starting in commits and prescribes a neat, progressive movement and linearity within the changes.
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! Begin with the lastest design file to reduce conflicts as well as unnecessary rebases.
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
The module has introduced you integration of GitHub with Git in a well-rounded way that imparted knowledge in essential skills related to version control. These activities combine theory with practice so that you get to take out in how to create and clone repositories into your own local machine. And understand remote repositories, finding out what they are and taking in their features, operations, and even issues relating to web hosting.
You are now in a good position to effect local changes using fundamental operations like modify, stage, and commit. With bringing the fetch command into use, you are also able to update yourself at any time. Besides, the effectiveness of safety measures would have been underlined using the secure shell as well proper handling of API keys with respect to safety on typing exercises.
The last lesson provided knowledge about how conflicts are resolved; in particular, it opened up the pull-merge-push workflow to you. Further use of the module as taught will make you efficient in conflict resolution, pushing the remote branch, and mastering the rebase process of your changes. Overall, it lays out the required foundation for a robust working relationship using Git and GitHub and enhances a way of understanding how collaborative working aspects may accentuate the skill of scholastics from coding projects.