Uncategorized

26:Using GitHub

Using GitHub

GitHub (www.github.com) is an online storage for your code. You can upload a copy of your code just after writing. You can also share it with your friends and colleges who are working on the same project with you. Your code will be reached to them in the proper way and when they will upload any changes, you are able to get in your local machine. GitHub is an essential requirement for building professional applications. Developing a software is a continuous process so it is also possible to change often and also want to revert the changes in code. GitHub will also manage the versions of your code that’s also called Version Control System.

  1. GitHub is online.
  2. You are required to install a local client for it on your machine.
  3. You have to sign up on www.github.com to upload the code.
  4. You can share your code and also can get already shared code.
  5. GitHub stores the code in the form of Repository.
  6. A repository may contain the code of one or more projects.
  7. VS Code and other code editors have facilities for creating, uploading, downloading and managing repositories in your system.
  8. GitHub also works independently, and if you are working on such a code editor that has no facility for it, you can still use it.
  9. GitHub is also very useful for deploying your code on production servers and computers.
  10. There are small project management facilities like task assignment and work progress are also available.

Setup and Installation

  1. Download the latest version of GitHub client from https://git-scm.com/downloads/win.
  2. This is for windows. If you are using something else, then download accordingly.
  3. This client tool manages GitHub repos on your local machine.
  4. Consider that GitHub client is an independent application that can be integrated to VS Code, Android Studio, Visual Studio, Net Beans or any other code editor.
  5. If you are working with such editor which is not integrate able with Git client (i.e. Dev-C++) then you can still use it as an independent application that manages all the said operations.
  6. The base edition is command based but there is also a GUI based edition, GitHub Desktop, available.
  7. For this lecture we will not use GitHub client independently, we just integrate it with our VS Code and use it.
  8. You will get an exe file, double click to run it. The installation wizard will start. This wizard seems longer than normal apps but you can continue with default values with the next button.
  9. After installation you must have Git Bash. Open the start button and type Git and you can see.
  10. After installation open VS Code. If VS Code was open during installation, then it is required to reopen.
  11. VS Code is an intelligent application that automatically integrates with Git client and doesn’t have to need some extensions for. Remember that there are some extensions available that help to manage the repos on local and online.
  12. If you see the following screen, then you are successfully installed and integrate the Git client with VS Code.

Figure 1: Git Window in VS Code

  1. You may have seen one or both buttons in the window.
  2. Now sign in (or sign up if not already) to www.github.com. You can use your Gmail or Apple ID.
  3. GitHub is very security sensitive; you must have to use Authenticator every time you login to GitHub.
  4.  Now you have two paths
  5. Create a repository in your local machine (inside VS Code) and upload to GitHub.
  6. Create a repository online and get it in your local machine (inside VS Code).
  7. If you are a project initiator or solo programmer then it is good to create a local project and upload.
  8. If a project is already under development and you just join the team, then you have to download it.
  9. The process of downloading in the code editor is called Cloning.

Creating and Uploading Repo

  1. A project may have one or more files and it is always good to create a folder in your local drive and open it in VS Code. We created “GitRepoLocal”.
  2. Create a new Python code file and write code of simple addition of numbers.

Figure 2: Simple Experiment file for GitHub Repo

  1. Open the activity bar and open the Git window.
  2. Click on the “Initialize Repository” button here.
  3. It will create a local repository on your local machine.

Figure 3: Creating Repo on Local

  1. After clicking on the “Initialize Repository” button, the window will be changed like this.
  2. Now it is time to understand some jargon for GitHub.

Figure 4: New Repo in Local

  1. When you make any change (even a single character or space) in any code file, the Git client detects it and informs you that you have made some changes and these are required to upload.
  2. Stage: You have the choice to make changes to be the part of your local repo. It is possible that some of the changes are still you working on and not ready for ship.
  3. The changes you have been confirmed, first stage them. You can see a + symbol against your file name and see tip “Stage Changes”. By clicking this + button, your changes are ready to be part of the local repo.
  4. Commit: Once the changes are staged, you can put them into the local repo. Click the commit button. Remember that you must have to enter a message for it. This is some sort of details of changes.
  5. Push: When changes are added to a local repo, you can ship it online but if your repo is not online then first it is required to publish.
  6. Publish: You newly created repo will upload to www.github.com
  7. Click on the “Publish” button and it will ask you to login in GitHub. A small process will login you and your VS Code will know about your GitHub account.
  8. After successful login, you can see the following screen.

Figure 5: Repo is ready to Publish Online

  1. Click on the selected repo in the middle window.
  2. Progress will continue in VS Code. Everything will be disabled for a while.

Figure 6:Publishing Progress

  1. It may ask again to login.
  2. When the process is completed, everything will be enabled again.
  3. To confirm that your repo is published online, open an account in the browser and you can see your repo in your online repos list.

Figure 7: Repo in Online Setup

  1. You can see that your repo is private, meaning other people cannot find your repo in search but your co-workers still can be the part of repo, change it and push.
  2. Now if make any change, even a single character, the Git client ready for stage, commit and push.
  3. You can see that GitHub automatically knows that Python code in your files and similarly, timestamp also records.
  4. You can click on the repo name to go on the repo dashboard to perform further operations.
  5. On the repo dashboard, you can perform many operations like watching history. You can see that all changes are pushed by all contributors. You can assign tasks by Issues and get ready the code for production using Actions, change settings, add/remove contributors or even delete the repo.

Cloning Repo

  1. When some repository creator adds you as a contributor, you have to download it to your local machine. This process is called cloning.
  2. For cloning the repo, it is necessary that you must have rights and links to get it.
  3. We have an online repo and consider that we have already been added as contributors. The creator or admin shared this link https://github.com/QN2135/RepoOnline
  4. Open VS Code and go into File->Close Folder if some folder is already open in it.
  5. In the activity bar, click on Source Control and click on “Clone Repository” or click on “Clone Git Repository” in the welcome window.

Figure 8: Cloning Repo from Online

  1. Enter the link in the command pallet.

Figure 9: Providing the Online Path

  1. Click on “Clone from URL”. It will open a save dialog. Select the folder where you want to download the repo.
  2. It will take some time to download, depending on the size of the repo. Once it is downloaded, it will ask to open. Click on the open button.
  3. It will create a sub-folder in it and the name of the folder will be the same as the online repo.
  4. We have created a simple Python code file in this repo and you can open it in your VS Code window.

Figure 10: Open Folder and File of Repo

  1. If we write the code of subtraction as mentioned in the comment in the file and save it, it will ask for stage, commit and push the changes.
  2. If you have a repo in your machine and some other contributor made changes in it and push and you want to get these changes then this process is called Pull.
  3. For example, these lines are added in the subtraction.py file.

Figure 11: New Changes in File

  1. Open the repo folder in VS code if not opened already, go in the Source Control window and click on three dots against the “Changes”. A menu will be open. Select Pull from it.

Figure 12: Pulling Repo

  1. It will take a few moments and we get updates in subtraction.py on local.

Figure 13: Updated File

Leave a Reply

Your email address will not be published. Required fields are marked *