Getting Started With GitHub

Github can be challenging for many reasons. It may look complicated, especially if you are using it for the first time. I struggled to find the significance of it. If Github was so vital, why did we have Git, git bash, and then Github online? What was the whole point of having 3 platforms if one could do the job of all.

Why is Github important

The founder of Github, Linus Torvalds, wanted to make it possible for several people to work on the same code without conflict.

Imagine you are working on the same document with different people, but this time it is code. Anytime you try to implement what you've written, you'll see changes made that, although valid and helpful, alter your entire code. This is the problem GitHub solves, it allows several people to work on the same document separately while adding every new change to a "main branch" after it has been validated. In this article, you will learn about the basic activities you can carry out on GitHub.

Github is a cloud service that allows you to share and track several versions ' your code online. Think of it as Google Docs on steriods

Git, on the other hand is a version control system you can use on your local drive (your laptop or computer). It allows you to create different versions of the same code and work on it without the internet. To download Git click here

You might find yourself confusing Git for Github or vice versa, but you'll soon find that they work together, and you'll be using both interchangeably

Creating a Remote Repository

A repository is a home for all your projects's files and folders. If you are working on, say, a school project, and you want to have it all in one place, you can save it in a repository. Creating a repository is simple. Sign up on Github, head over to your profile and click on new Congratulations you have created a remote repo on GitHub

image.png

Creating a Local Repository: lets say you have write some code in VS Code, now you want move your code from your code editor to a local repo in Git, that will allow you create & manage several versions of your code. here are the steps to do that

image.png

  • Download GitBash
  • Locate the folder where the file code is saved in -> cd desktop/File Folder/ File Folder/File
  • Initialize your git -> git init
  • Add the stated file to git command -> git add .
  • Assign a message to your repo -> git commit -m "Commit message"
  • Confirm the status of your repo -> git status

Pushing your Code to Github : Remember the remote repo we created earlier, we can now push our codes from our local repo that we have just created, to the remote repo that we created in Github. To do this, simply add this command to your screen

  • Push the file to the online repo -> git push -u "file name"

. Creating a branch: Creating to branch is used when you want to make changes to your code while keeping the main content intact. in this branch you can make or add changes, which can be merged with the main branch after it has been valided from a pull request, we will work through a process of creating a branch from this code

  • Name your branch -> git branch
  • Check out of the main branch -> git checkout -u main (this takes you to the new branch to add changes)
  • Add code to new branch -> git add .
  • Add comments to your new branch -> git commit -m "Commit Message"

Pushing a branch At every point, you want to have the most updated version of your local document, it is the same as pushing your own code, follow the process you used in pushing your code, look out for the slight change that shows your out of the main repo and now in the branch of the same file

Sending a Pull Request Before a new branch is added to a side branch, a pull request is sent. A pull request as it is called is a "request" for another Github user to review your code . if they accept this request, you give them the right to access your code and add it to the main branch. to send a pull request;

  • go back to your new branch -> git checkout main
  • send your pull request -> git pull origin

If you are having a hard time learning this, don't worry, instead, try creating new files in different languages, try adding them on your local repository, send it to the remote repository, grab source codes from developers all over the world, and send pull request. with a lot of practice, you will get better with time.

If you have any question please reach out via mail or tweet at me WildFlower.Eth🌺

Resources

  1. Git vs Github: whats the difference

  2. Git's local repository and remote repository

  3. Getting Started with Git

Â