ഈ assignment ഇന്റെ നീട്ടം നോക്കണ്ട 😂 All is well. നമുക്ക് പതിയെ ചോദിച്ചു ചോദിച്ചു ചെയ്യാം.
Just like knowing how to use the Command Line, Git & Github will be very important in your daily workflow as a programmer / developer.
Let’s put your Git and GitHub skills to practice! Find the assignment below.
- The assignment has to be done strictly in a PC.
- You can either use WSL and ubuntu from your windows machine or use any Linux OS as standalone or use a virtualbox with any Linux OS in it.
- Do not do the assignment in powershell or cmd.
- Try the command
git --version
in your shell. If it returns a git version, it means git is installed. If it shows an error message, you need to install git. - Go to https://git-scm.com/downloads to download git for your OS. (If you’re using WSL and doesn’t have git, choose Linux/Unix version of git when downloading)
Once Git is installed setup your global config values if you haven’t. Run the commands:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Replace the parts in quotes with your info.
Setup is done! You’re good to go.
Create an account in https://github.com/ → Sign Up.
You might wonder what really this is, and why you need to do this setup (എന്തിനു നിങ്ങൾ ഇത് ചെയ്യണം?)
Let’s refer to our machine as ‘local machine’, where we use git ‘locally’ for version control. We refer to GitHub as ‘remote’, this is where we push our project files to using git from our local machine.
So, GitHub is a service something like Google drive. To save our files or to make changes to our data in Google drive we need to login with our google account. Right? The same applies for GitHub. GitHub needs to know it is the right user trying to push files to a particular GitHub account. (ആരാണെന്നു മനസിലായില്ലെങ്കിൽ GitHub സമ്മയ്ക്കൂല 🤧 )
So the question is how would GitHub know it is you, the right user trying to push files to a particular GitHub account from a local machine using git?
Using SSH Keys (താക്കോൽ എവിടെ? 🤔 ) GitHub has the feature to use SSH keys to establish a secure, authenticated way of data transfer. It would basically ensure you are the right user. So let’s setup SSH keys for your GitHub account.
This wasn’t covered in the session, but it’s fairly easy to do. Follow the steps below.
- Open your terminal.
- Make sure you are in your home directory. (It will show a ~)
- Type
ls -a
It will list all hidden files. See if you can find. the.ssh
directory in it. - If you can’t find it in the list, create the
.ssh
directory. - Now, let’s generate an SSH key pair. Use the command
ssh-keygen -t ed25519 -C*"[email protected]"*
- It will ask you for a file to save the key. Press Enter for now.
- You will now be asked for a passphrase. You don’t have to set a passphrase. You can press Enter twice.
- You’ve now created a SSH private and public key. We will be using the private key in your local machine and we’ll add the public key to your Github.
- Now do the command
eval "$(ssh-agent -s)"
It will start an ssh agent in the background. - Now let’s add you ssh key to the ssh-agent.
- Do the command
ssh-add ~/.ssh/id_ed25519
You’ve now successfully created and added your SSH key to your local machine. (നമ്മൾ പൊളി ആണ് ⚡)
Adding SSH key to your GitHub account
As we mentioned before, your GitHub needs to know it is the right user trying to connect with GitHub from a local machine.
So we’ll add the public key of your SSH to your GitHub account. Follow from step 1 in this link to add your SSH public key to your GitHub account.
Now as we said earlier, you’ve successfully setup an authentication method between Github( the remote), and your local machine. Hip Hip Hurray! 🥂 (പെവെർ 😎 💪 )
The Assignment:
- Let’s write a book! You’re building a book app. It has the feature for the author to add a book. We’ll be working on that feature of the app today. (Don’t worry we’ll be using text files for now)
- Fork this repo - https://github.com/gtech-mulearn/Github-Enablment-Task
- Once the fork is made, clone the repo using the SSH option. (Google if you don’t know how to)
- After you’ve cloned it locally, do the list command, you should be able to see the repo now.
- Change directory into the cloned repo folder.
- Make a new branch called
develop
- Do a
git status
- You should now be able to see that the working tree is clean.
- Make another directory in the root of the app, with your full name. Eg:
bijoy_sijo_book_app
- Change directory into it.
- Now, create another directory inside your book app directory called
add_books_feature
- Let’s build some features in it now!
- Now let’s make two text files in your books_feature directory.
- Add a
create_book.txt
file. - Add the text
"This is the feature for the author to add a new book."
in to the create_book.txt file. - Let’s commit your change now.
- Next, create another file named
list_all_books.txt
- Add the text
“This is the feature which shows the user all the books they’ve created as a list.”
to the list_all_books.txt - Let’s add your change now.
- Add a
- Uh oh! You just realised that you don’t need to add the change made to list_all_books.txt now.
- Unstage the list_all_books.txt. (If you don’t know the command, try a
git status
and read the output 😉. or Google for it) - You realise that, since, list_all_books.txt is another feature, you decide to complete developing it on another branch. Checkout to main branch first and then create a new branch called
feature
and commit the list_all_books.txt file and it’s changes in that branch. - In the same feature branch, now let’s make another change, to your list_all_books.txt file add the text
"List all books will list all books in ascending order."
You just added a new feature. - Check the log to see the changes you’ve made so far.
- Let’s commit it. Your feature branch should ideally have a minimum of two commits now.
- Now, to push back your changes and conrtibute your code to the GTech µLearn Github repository, you need to raise a Pull Request (പേടിക്കണ്ട നമുക്ക് സെറ്റ് ആക്കാം).
- But before that, remember that you now have two different branches, namely,
develop
andfeature
The commits you made so far are in two branches. Let’s merge them together to get a complete project with all features and then push back to the GTech µLearn Github to raise a Pull Request. - Checkout to the
develop
branch and then merge thefeature
branch into develop branch. - Once the merge is complete. Push the develop branch to the remote.
- Navigate to your forked repo in your Github.
- Find the option to open a PR. Open your PR from your develop branch to the main branch of the GTech µLearn repo. Give your PR a meaningful title and description. Open the PR.
You’re a superstar! You just learned the basic Git & Github workflow! 🥳
Now if you go to the pull requests tab in GTech µLearn repo, you’ll be able to see your pull request. Open it and copy your pull request URL.
- Submit the link in #task-dropbox channel with the hashtag,
#ge-git-github
- With your submission, feel free to drop in a small note about your experience with doing this assignment. 😄 We’d be delighted to read it.
Refer to the session recording here → https://www.youtube.com/watch?v=Bg2U_Cgp3K0&ab_channel=GTechµLearn
Google is your best friend. You can refer to other simple Git and GitHub videos in YouTube.