update module3.ipynb

This commit is contained in:
Yavuz Sava 2025-03-07 23:33:36 +03:00
parent f5dc54d19f
commit b6f54c134e

View File

@ -2064,7 +2064,22 @@
"metadata": {},
"source": [
"# Study guide: Conflict resolution\n",
"\n"
"\n",
"In Git, merge conflicts, or conflicts that occur when merged branches have competing commits, are not uncommon when working with a team of developers or when working with open-source software. This study guide provides you with tips for resolving merge conflicts. \n",
"\n",
"## Tips for resolving merge conflicts\n",
"\n",
"Here are some tips to keep in mind when youre resolving merge conflicts: \n",
"\n",
"- After running Git merge, a message will appear informing that a conflict occurred on the file.\n",
"- Read the error messages that imply you cannot push your local changes to GitHub, especially the remote changes with Git pull.\n",
"- Use the command line or GitHub Desktop to push the change to your branch on GitHub after you make a local clone of the repository for all other types of merge conflicts.\n",
"- Before merging any commits to the master branch, push it into a remote repository so that collaborators can view the code, test it, and inform you that its ready for merging.\n",
"- Use the Git rebase command to replay the new commits on top of the new base and then merge the feature branch back into the master.\n",
"\n",
"## Key takeaways\n",
"\n",
"It is important to effectively resolve merge conflicts because local changes cannot be made to Git until the merge conflicts have been locally resolved. Once all conflicts have been resolved, changes can be pushed to Git and merged in a pull request."
]
},
{
@ -2072,14 +2087,378 @@
"metadata": {},
"source": [
"# Glossary terms from module 3\n",
"\n"
"\n",
"## **Terms and definitions from Module 3**\n",
"\n",
"**Application Programming Interface (API) key:** This is an authentication token that calls an API, which is then called to identify the person, programmer, or program trying to access a website\n",
"\n",
"**Computer protocols:** Guidelines published as open standards so that any given protocol can be implemented in various products\n",
"\n",
"**Distributed:** Each developer has a copy of the whole repository on their local machine\n",
"\n",
"**GitHub:** A web-based Git repository hosting service, allowing users to share and access repositories on the web and copy or clone them to a local computer\n",
"\n",
"**Merge:** An operation that merges the origin/master branch into a local master branch\n",
"\n",
"**Private key:** A secret and secure cryptographic key that must be kept confidential and protected and is used to decrypt data that has been encrypted with the corresponding public key\n",
"\n",
"**Public key**: A safety cryptographic structure frequently employed to establish secure communication through data encryption or to validate the authenticity of a digital signature\n",
"\n",
"**Rebasing:** The base commit that's used for a branch is changed\n",
"\n",
"**Remote branches:** Git uses read-only branches to keep copies of the data that's stored in the remote repository\n",
"\n",
"**Remote repositories:** Repositories that allow developers to contribute to a project from their own workstations making changes to local copies of the project independently of one another\n",
"\n",
"**Secure Shell (SSH):** A robust protocol for connecting to servers remotely\n",
"\n",
"**SSH client:** This  establishes a connection to the SSH server, ensuring a secure interaction, where the client makes access requests\n",
"\n",
"**SSH key:** An access credential\n",
"\n",
"**SSH protocol:** Standard commonly used for logging in to servers remotely on the principle of public-key encryption\n",
"\n",
"**SSH server:** This establishes secure network connections, undergoes mutual authentication, and initiates encrypted login sessions or file transfers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exemplar: Introduction to GitHub"
"# Exemplar: Introduction to GitHub\n",
"\n",
"## Introduction\n",
"\n",
"In the previous lab, you practiced the basics of interacting with GitHub. You practiced setting up an account, logging in, creating a repository, making changes on the local machine, and pushing changes back to the remote repository. We used these git operations to share changes from the remote repository to the local repository and vice-versa.\n",
"\n",
"This exemplar is a walkthrough of the previous Qwiklab activity, including detailed instructions and solutions. You may use this exemplar if you were unable to complete the lab and/or you need extra guidance in competing lab tasks. You may also refer to this exemplar to prepare for the graded quiz in this module.\n",
"\n",
"## Create a git repository\n",
"\n",
"To create a git repository, you need to have a Github account. Follow the steps below to create a github account and a git repository:\n",
"\n",
"- Open [Github<svg aria-labelledby=\"cds-react-aria3604314262-:r7ti:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r7ti:\"><title id=\"cds-react-aria3604314262-:r7ti:-title\">Opens in a new tab</title></svg>](https://github.com/join). If you don't already have a Github account, create one by entering a username, email, and password. If you already have a Github account proceed to the next step.\n",
"- Log in to your account from the [Github<svg aria-labelledby=\"cds-react-aria3604314262-:r7tk:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r7tk:\"><title id=\"cds-react-aria3604314262-:r7tk:-title\">Opens in a new tab</title></svg>](https://github.com/) login page.\n",
"- Click the **+** sign in the top-right corner of the page and click then on **New repository**.\n",
"\n",
"![A dropdown menu with options to create a new repository, as well as other options.](https://d3c33hcgiwev3.cloudfront.net/imageAssetProxy.v1/8SSESwLQReuSlLjftBc1Fw_3ed21e90cb774ac1b5e0300f5500a7f1_dmCVrIRHpQ36U3-2F0oxb-2B6uICGLfFpbG4LtuWGLzNBbQ-3D?expiry=1741478400000&hmac=6sWT-yzQMLYJz-KnRaNaKi8HBfWEDCeWwfqgdM6Wp0M)\n",
"\n",
"- Enter your repository name in the field **Repository name** and add a project description in the **Description** field.\n",
"- You can either select **public** or **private** to restrict repository accessibility. If **public**,anyone can see the repository but you still choose who can commit to it. If **private**, you choose who can see and commit to the repository.\n",
"- Check the option **Initialize this repository with a README** to initialize the repository with a README file. Leave all the other values to their default.\n",
"- Click the **Create repository** button.\n",
"\n",
"## Git operations\n",
"\n",
"You now need to create a local copy of this remote repository on your machine. We'll do this by cloning the repository. The syntax for this is:\n",
"\n",
"```bash\n",
"git clone \\[URL\\]\n",
"```\n",
"\n",
"For the URL, you can either choose an **SSH** or an **HTTPS** link as a URL. We will use HTTPS to clone the Git repository. Click on **Clone or download** and select HTTPS. Copy the **HTTPS** link by clicking on the Copy button beside the link.\n",
"\n",
"![A button labeled \"Use HTTPS\" on a web page.](https://d3c33hcgiwev3.cloudfront.net/imageAssetProxy.v1/uiioNP38QOiiKt4FBmymsg_3dc188689e134ccc81ea2fd799d1bef1_xxNbKG7cXU0JeU84ZtZRwETyRJsC5-2B3-2BxQqD3OyVWaU-3D?expiry=1741478400000&hmac=w7VschU63mwM1op05TJBZCgkvCvx2C4w4KYQmk4Wj78)\n",
"\n",
"Next, in the provided **terminal**, replace \\[URL\\] from the above syntax with the link you copied. The command should now look similar to:\n",
"\n",
"```bash\n",
"git clone https://github.com/\\[username\\]/\\[git\\-repo\\].git\n",
"```\n",
"\n",
"Here, **username** is the Git username and **git-repo** is the name of the remote repository you created.\n",
"\n",
"\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\n",
"\n",
"***Note:*** *If you are using a* ***private*** *repo, then you will need to use your Github username and personal access token to clone the repo via HTTPS method as password authentication method is currently not supported by Github.*\n",
"\n",
"*It requires the use of personal access tokens rather than traditional passwords so it is necessary for you to create a personal access token to complete the lab (in case you dont have one). Also this token will be used in further steps for the lab.*\n",
"\n",
"***Generating a Personal Access Token***\n",
"\n",
"***Personal Access Token*** *can be created by moving the application settings of your Github account. Proceed to the* ***Settings*** *menu and choose* ***Developer settings****, where you will locate the option for* ***Personal Access Token****. By utilizing this token, you will be enabled to clone and push to your remote repository using HTTPS. For more help to generate a personal access token, click* [*here*<svg aria-labelledby=\"cds-react-aria3604314262-:r7u0:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r7u0:\"><title id=\"cds-react-aria3604314262-:r7u0:-title\">Opens in a new tab</title></svg>](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token)*.*\n",
"\n",
"\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\n",
"\n",
"This creates a directory with the same name as your repository, initializes a **.git** directory inside it, pulls down all the data for that repository, and creates a working copy of the latest version.\n",
"\n",
"You can now list the files using the **ls** command and find your new repository. Move into your repository using **cd** command. There, you'll see the project files, which are ready to be worked on or used.\n",
"\n",
"```bash\n",
"cd directory\\_name\n",
"```\n",
"\n",
"Replace the **directory\\_name** with your repository's name that you just initialized.\n",
"\n",
"If you want to clone the repository into another directory of your choice, you can do that by passing the name of the directory. This automatically creates a new directory with the specified name and initializes the repository inside it.\n",
"\n",
"**Syntax:**\n",
"\n",
"git clone \\[URL\\] directory\\_name\n",
"\n",
"## Configure Git\n",
"\n",
"Git uses a username to associate commits with an identity. It does this by using the **git config** command. Set Git username with the following command:\n",
"\n",
"```bash\n",
"git config \\--global user.name \"Name\"\n",
"```\n",
"\n",
"Replace **Name** with your name. Any future commits you push to GitHub from the command line will now be represented by this name. You can use **git config** to even change the name associated with your Git commits. This will only affect future commits and won't change the name used for past commits.\n",
"\n",
"Let's set your email address to associate them with your Git commits.\n",
"\n",
"```bash\n",
"git config \\--global user.email \"user@example.com\"\n",
"```\n",
"\n",
"Replace **user@example.com** with your email-id. Any future commits you now push to GitHub will be associated with this email address. You can also use **git config** to even change the user email associated with your Git commits.\n",
"\n",
"## Edit the file and add it to the repository\n",
"\n",
"Now, edit the README file by using nano editor:\n",
"\n",
"```bash\n",
"nano README.md\n",
"```\n",
"\n",
"Add any text within the file, or you can use the following text:\n",
"\n",
"```bash\n",
"I am editing the README file. Adding some more details about the project description.\n",
"```\n",
"\n",
"Save the file by pressing **Ctrl-o**, **Enter** key, and **Ctrl-x**.\n",
"\n",
"We can check the status using the following command:\n",
"\n",
"```bash\n",
"git status\n",
"```\n",
"\n",
"The git status command shows the different states of files in your working directory and staging area, like files that are modified but unstaged and files that are staged but not yet committed.\n",
"\n",
"You can now see that the README.md file shows that it's been modified.\n",
"\n",
"**Output:**\n",
"\n",
"```bash\n",
"On branch main\n",
"\n",
"Your branch is up to date with 'origin/main'.\n",
"\n",
"Changes not staged for commit:\n",
"\n",
"  (use \"git add <file>...\" to update what will be committed)\n",
"\n",
"  (use \"git checkout -- <file>...\" to discard changes in working directory)\n",
"\n",
"        modified:   README.md\n",
"\n",
"no changes added to commit (use \"git add\" and/or \"git commit -a\")\n",
"```\n",
"\n",
"Now, let's add the file to the staging area using the following command:\n",
"\n",
"```bash\n",
"git add README.md\n",
"```\n",
"\n",
"Use the **git add** command to add content from the working directory into the staging area for the next commit. When the git commit command is run, it looks at this staging area. So you can use git add to craft what you'd like your next commit snapshot to look like. To check the files in staging area use git status.\n",
"\n",
"**Output:**\n",
"\n",
"```bash\n",
"On branch main\n",
"\n",
"Your branch is up to date with 'origin/main'.\n",
"\n",
"Changes to be committed:\n",
"\n",
"  (use \"git reset HEAD <file>...\" to unstage)\n",
"\n",
"        modified:   README.md\n",
"```\n",
"\n",
"Let's now commit the changes. A Git commit is like saving your work.\n",
"\n",
"Commit the changes using the following command:\n",
"\n",
"```bash\n",
"git commit\n",
"```\n",
"\n",
"This now opens an editor that asks you to type a commit message. Every commit has an associated commit message. A commit message is a log message from the user describing the changes.\n",
"\n",
"Enter the commit message of your choice or you can use the following text:\n",
"\n",
"```bash\n",
"I am editing the README file.\n",
"```\n",
"\n",
"Once you've entered the commit message, save it by clicking **Ctrl-o** and the **Enter** key. To exit click **Ctrl-x**.\n",
"\n",
"The **git commit** command captures a snapshot of the project's currently staged changes. It stores the current contents of the index in a new commit along with the commit message.\n",
"\n",
"You've successfully committed your file!\n",
"\n",
"Now, push the committed changes from your local repository to a remote repository on the **main** branch by using:\n",
"\n",
"```bash\n",
"git push origin main\n",
"```\n",
"\n",
"Next, enter your Github username/email ID and personal access token on password prompt to push the changes on the associated remote repository.\n",
"\n",
"**Note:** If you have cloned a private repository, you would have already generated a personal access token. Therefore, utilize that token to push the changes. In case you are using public repo, please refer to the steps for **Generating a Personal Access Token** provided earlier in the section **Git operations**.\n",
"\n",
"You can check the changes made to the local README.md file on the remote repository on [Github<svg aria-labelledby=\"cds-react-aria3604314262-:r7vu:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r7vu:\"><title id=\"cds-react-aria3604314262-:r7vu:-title\">Opens in a new tab</title></svg>](https://github.com/). You can see the last time when the README.md file was added/updated.\n",
"\n",
"You can also see the commit ID just above the list of files in the repository. Click on the Commit ID to get more details related to the commit.\n",
"\n",
"![A GitHub repository interface showing a README file being edited.](https://d3c33hcgiwev3.cloudfront.net/imageAssetProxy.v1/6s2qbamGRci2Ky3S4KsOnQ_bd97592d5229495bba6759a6c937a1f1_202ufHqbdeGDT6cP7tgJWIccoyHhTPniulusE3cL4eY-3D?expiry=1741478400000&hmac=P_c6cpZ-gOjPWnCE6mP50Ij4zblvJTMX2SCdjG6huJY)\n",
"\n",
"## Create a new file and commit it to the repository\n",
"\n",
"You now need to create a new file **example.py** on the local git repository in the working directory. To do this, use the following command:\n",
"\n",
"```bash\n",
"nano example.py\n",
"```\n",
"\n",
"Add the following Python script to the **example.py** file:\n",
"\n",
"```bash\n",
"def git\\_opeation():\n",
"\n",
" print(\"I am adding example.py file to the remote repository.\")\n",
"\n",
"git\\_opeation()\n",
"```\n",
"\n",
"Save the file by pressing **Ctrl-o**, **Enter** key, and **Ctrl-x**.\n",
"\n",
"Now, repeat the same procedure by adding a file to the staging area for next commit:\n",
"\n",
"```bash\n",
"git add example.py\n",
"```\n",
"\n",
"Commit the changes:\n",
"\n",
"```bash\n",
"git commit\n",
"```\n",
"\n",
"Enter a commit message and save it by pressing **Ctrl-o** and the **Enter** key. To exit click **Ctrl-x**.\n",
"\n",
"We will push these changes later in the lab.\n",
"\n",
"## Add an empty file to the repository through web UI\n",
"\n",
"Now, let's create an empty file on the remote repository using the Github website.\n",
"\n",
"1. Go to your repository on the Github website and click on the **Add file** button, then click on **Create new file**. This will open a new page.\n",
"\n",
"![A button labeled \"Create new file\" on a web page.](https://d3c33hcgiwev3.cloudfront.net/imageAssetProxy.v1/QEjsBy2tSZCQQR9uwOi4BA_6b66a83b66864e5f8bda19d6a4fa0af1_Cqsv9hGI56IUvL9-2BI-2F1mVbFcyRb6kGPehEG3b9IJ0Lc-3D?expiry=1741478400000&hmac=a7lMySA4iuVhkfUcQZ8Tr8ibsbfpt2IBE7nwDCAQnQM)\n",
"\n",
"1. Enter the file's name in the box beside your repository's name. Leave the contents of the file empty.\n",
"2. On the right side, click on **Commit changes...** button.\n",
"3. Leave the rest on its default value and click the **Commit changes** button.\n",
"\n",
"You've successfully committed a new file through the website.\n",
"\n",
"Now, let's push the changes made on the local repository that weren't pushed. Switch back to your terminal and enter the following command:\n",
"\n",
"```bash\n",
"git push origin main\n",
"```\n",
"\n",
"**Output:**\n",
"\n",
"```bash\n",
"Username for 'https://github.com': XXXXXXXX\n",
"\n",
"Password for 'https://XXXXXXXX@github.com': \n",
"\n",
"To https://github.com/XXXXXXXX/testlabs.git\n",
"\n",
" ! \\[rejected\\]        main -> main (fetch first)\n",
"\n",
"error: failed to push some refs to 'https://github.com/XXXXXXXX/testlabs.git'\n",
"\n",
"hint: Updates were rejected because the remote contains work that you do\n",
"\n",
"hint: not have locally. This is usually caused by another repository pushing\n",
"\n",
"hint: to the same ref. You may want to first integrate the remote changes\n",
"\n",
"hint: (e.g., 'git pull ...') before pushing again.\n",
"\n",
"hint: See the 'Note about fast-forwards' in 'git push --help' for details.\n",
"```\n",
"\n",
"The last command throws an **error**. This is because the files added or change done on a remote repository (the Github website) isn't present yet on your local repository, but we're trying to push something from the local repository to the remote repository. To push changes from the local repository, we need to first update the local repository from the remote repository.\n",
"\n",
"Let's now pull the current snapshot/commit in the remote repository to the local repository:\n",
"\n",
"```bash\n",
"git pull origin main\n",
"```\n",
"\n",
"This opens an editor that asks you to enter a commit message for the merge operation (remote repository to local repository).\n",
"\n",
"You can simply accept the default message or type your own message. To continue, save the file by pressing **Ctrl-o**, **Enter** key, and **Ctrl-x**.\n",
"\n",
"The git pull command is used to fetch and download content from a remote repository and update the local repository to match that content.\n",
"\n",
"**Output:**\n",
"\n",
"```bash\n",
"Merge made by the 'recursive' strategy.\n",
"\n",
" file | 1 +\n",
"\n",
" 1 file changed, 1 insertion(+)\n",
"\n",
" create mode 100644 file\n",
"```\n",
"\n",
"Now try pushing the changes again.\n",
"\n",
"```bash\n",
"git push origin main\n",
"```\n",
"\n",
"**Output:**\n",
"\n",
"```bash\n",
"Username for 'https://github.com': XXXXXXXX\n",
"\n",
"Password for 'https://XXXXXXXX@github.com': \n",
"\n",
"Enumerating objects: 7, done.\n",
"\n",
"Counting objects: 100% (7/7), done.\n",
"\n",
"Compressing objects: 100% (5/5), done.\n",
"\n",
"Writing objects: 100% (5/5), 613 bytes | 306.00 KiB/s, done.\n",
"\n",
"Total 5 (delta 1), reused 0 (delta 0)\n",
"\n",
"remote: Resolving deltas: 100% (1/1), done.\n",
"\n",
"To https://github.com/XXXXXXXX/testlabs.git\n",
"\n",
"   e75d9dd..2d11936  main -> main\n",
"```\n",
"\n",
"This shows that your local repository is now up-to-date with your remote repository and you successfully pushed the changes to the remote repository.\n",
"\n",
"## Congratulations!\n",
"\n",
"Great job! You've successfully set up a Github account, logged in, created a repository, made changes on the local machine, and pushed changes back to the remote repository. You've learned how to share local changes from a local to remote repository and vice-versa. These skills will help you as an IT specialist to work with a remote user on the same repository."
]
}
],