Git and GitHub: A Beginner's Guide

Git and GitHub: A Beginner's Guide

What is Git?

Git is a Free and open source version control system. Most programmers interact with Git on a daily basis.

What is Version Control?

The management of changes to documents, computer programs, large websites and other collections of information.

Some of the terms used in GitHub

  1. Directory: Folder.
  2. Terminal or Command line: Interface for Text commands.
  3. CLI: Command Line Interface.
  4. CD: Change Directory.
  5. Code Editor: Word Processor for Writing Code.
  6. Repository: Project, or the folder/place where your projects is kept.
  7. GitHub: A website to host your repositories online.

Git Commands:

  1. Clone: Bring a repository that is hosted somewhere like GitHub into a folder on your local machine.
  2. add : Track your files and changes in Git.
  3. commit: Save your files in Git.
  4. push: Upload Git commits to a remote repo, like GitHub.
  5. pull: Download changes from remote repo to your local machine, the opposite of push.

First thing you will need to do is Sign Up for an account on GitHub you will get an Email and asking to verify and then login to your account.

github_signup.png

Once you logged in you can see the below profile page which you can access from the top right dropdown menu or you might be on the dashboard page and create a new repository.

github_signin.png

How to create a new Repository? On the top right click on new Repository and give it a name as Ex: demo-repo, add description and click create repository.

create-new-repo.png

Now, you can create a files and folders inside the repository locally on your machine or online editor on the website.

demo-repo.png

Now, create a README.md file and commit new file.

Installation of Git:

Install https://git-scm.com/downloads by clicking on this link here

install git.png

Step 1 : Verify Installation: To verify if git is installed locally run this command on your terminal or cmd.

git --version

git v.png

If this command returns the version of your git that means git is locally installed and we are ready to go.

Step 2: Git Configuration: You have to set your username and email address. Git will use this to identify changes made by you. To do so, use these commands in terminal/cmd:

*git config --global user.name "YOUR_USERNAME"

git config --global user.email "YOUR_EMAIL_ADDRESS"*

Just make sure to put your email address and the username you want in the respective fields.

Step 3: Git Initialization

Initialize local Git repository

git init

git init.png

Step 4: Git add filename

The command, git add will add the file or files that you specify to the staging area or the index, and they'll be ready to commit..

To add all the all files in the entire repository to staging area you can use

git add .

Step 5: Check status of working tree

git status

git status.png

Step 6: When you are ready you can go ahead and commit your folder or files. It takes everything to the index or staging area and put it into the local repository.

> git commit -m “[ Type in the commit message]”

Step 7: Now push all the files to remote repository.

git push

Step 8: Now pull all the latest code from remote repository.

git pull [Repository Link]

Some of the other git commands and usages listed below:

git branch By using this command you can get a list of all the branches in your repository.

git clone [url] This command is used to obtain a repository from an existing URL.

git rm [file] This command deletes the file from your working directory and stages the deletion.

git log This command is used to list the version history for the current branch.

git checkout This command is used to switch from one branch to another.

git merge This command merges the specified branch’s history into the current branch.

git remote This command is used to connect your local repository to the remote server.

git stash This command temporarily stores all the modified tracked files.

Conclusion Git and GitHub are two of the most commonly used technologies in the software industry. In this article, I tried to give a brief introduction to Git and GitHub. Also, I have included a list of the most commonly used git commands and their usages.

Thank you

Happy Reading