INTRODUCTION TO GIT AND GITHUB

Nkemdili Ezike
7 min readNov 27, 2022

--

Git and GitHub are simple yet difficult-to-understand topics in software development. They are two of the most popular and powerful tools used in software development. They are both used to manage and collaborate on software projects. I know a lot of software newbies find it difficult to walk around this topic, I hope this little breakdown of Git and GitHub will go a long way in being a stepping stone to your full understanding of git and GitHub

WHAT IS GIT?

Git is a version control system. Version control also known as source control is the practice of managing and making changes to a file. That is, it records changes to a file or set of files so that you can easily get back the files when you lose them on your local system. There are other popular version control system such as Mercurial, SVN, Perforce e.t.c.

Git is a popular version control system. It is used for:

  1. Tracking code changes
  2. Tracking who made such changes
  3. Coding collaboration
  4. Reverting of codes
  5. Store, manage and share codes

DOWNLOADING GIT

  1. Click here to download GitHub to your local storage
  2. Choose your PC’s operating system and proceed to download
  3. Follow the instructions as provided in the Git Setup wizard screen until the installation is complete.

GITHUB

WHAT IS GITHUB

GitHub is a web-based code hosting platform for version control and collaboration. It provides the function of storage, bug tracking, code sharing, hosting of the git repository, and collaboration with anyone irrespective of their location. It also provides tools and features that enhance easy collaborations such as pull request, project management, issue tracking, issue tracking, e.t.c.

To use GitHub, proceed to https://github.com/ and signup for an account

GIT COMMAND LINES

A. SETTING UP THE GIT

  • Checking Git version: To check if your git is properly installed, you will:

a. Open your command prompt

b. Run the git — version command

  • git config — global user.name ”your name”: It lets git register your name. It is preferable to use the name generated for your gGitHubaccount.
  • git config — global user.email ”your email”: It lets git register your email
  • git config — list: List all Git configuration settings

This name and email will be used for every commit message that you make.

B. INITIALISING YOUR FIRST PROJECT

Create a folder in your local PC and create an index.html file. Open the folder in your text editor and run the following commands using the text editor terminal

  • git init: It initializes an empty repository in your local storage
  • git status: It tells us the status of the git or the changes made at any point in time. We have the track and untracked files. The untracked files are in the folder but the changes made are not tracked by git yet unlike the tracked files
  • git add . : Git tracks all the files in the folder once you run this command
  • git add filename: Git tracks a particular file once you run this command. The filename is the name of the file you want to add to your commit.
  • git commit -m”commit message”: It saves progress at different stages of the work in case you need to go back and make some edits. Your commit message must be descriptive.

C. GIT BRANCHING

It is used basically for collaboration. In this case, the collaborators get a branch where they can work separately before making a pull request to the main branch for merging.

  • git branch nameOfBranch: It creates a new branch. In the image below, develop is the name we gave to our branch.
  • git checkout -b nameOfBranch: It is a single CLI used to create a branch and check into the branch. In the figure below, we created and switched to a new branch called Navy.
  • git branch: It shows you all the branches that you have created. Navy is highlighted because it is the branch we are currently on.
  • git checkout nameOfBranch: It takes you or checks you into that particular branch

Here, we switched our branch from Navy to develop.

D. CREATING A REPO:

Log into your GitHub account on https://github.com/

  • In the upper-right corner of your page, click the drop-down menu or the plus sign icon, and select New repository.
  • Type a short, memorable name for your repository. For example, “hello-world”.
  • Type in the description of your repo
  • Leave the repository open to let people have access to the repository
  • Include a README and a gitignore if necessary
  • Then click on create repository

E. PUSHING CODE TO GITHUB

Copy the link from the GitHub repository and go back to your editor terminal

  • git branch -M main: It renames the default master branch to main
  • git remote add origin linkYouCopied: It links the local repo you created with git to the repo on the GitHub page
  • git remote -v: Shows you the available path/remote
  • git push -u origin nameOfBranch: It pushes a code to the specified branch.
  • git pull origin branchName: It pulls all the codes from the stipulated branch to the current branch you are working on

Here, it pulls in changes made in the develop branch into the current branch you are in.

F. CLONING A REPO:

Open a terminal in the folder you want to clone into

  1. git clone repoLink: ‘ repoLink’ is the link of the repository you want to clone

G. CREATING A PULL REQUEST

  1. Click on pull Request
  2. On GitHub, confirm that the branch in the base: drop-down menu is the branch where you want to merge your changes. Confirm that the branch in the compare: drop-down menu is the topic branch where you made your changes.
  3. Type a title and description for your pull request.
  4. To create a pull request that is ready for review, click Create Pull Request.

H. MERGING A PULL REQUEST:

  • Under your repository name, click Pull requests.
  • In the “Pull Requests” list, click the pull request you’d like to merge.

Merge all of the commits into the base branch by clicking Merge pull request

GREAT PRACTICES ON GITHUB

For great flow in uploading work on github, there are some practices you need to adhere to. They include:

  1. Make commits regularly in case you want to go back and make some changes to your previous work
  2. When collaborating with others, make sure to always create your own working branch to avoid conflicts. The work on the main branch should always be presentable at any point in time.
  3. When you make a pull request, endeavor to show a screenshot of the work you did or a caption for easy access before merging.

In conclusion, the ability of Git and GitHub to manage and collaborate on code has made it easier for people all around the world to work remotely and also collaborate on different projects thereby making Git and GitHub an integral part of the software development process.

--

--