General

How to create a Github repository and use Git – all Github commands list 2022

GitHub Repository Guide – a step-by-step guide on how to create GitHub repositories on VS Code and how to use GitHub.

Visual Studio Code is one of the foremost source code editing softwares for building, editing, and debugging codes. It was made by Microsoft in 2015 and has since gained popularity across several operating systems, due to its simplicity, and functionalities including support for debugging, syntax highlighting, intelligent code completion, snippets, refactoring, embedded git, and more.

GitHub is a cloud-based service for storing and sharing source code. On Github, you can share your source code and even collaborate with others.

Github is popular amongst software engineers, as there are lots of ways to interact with it, including;

  • Via the website at https://github.com
  • The Git command-line interface (CLI)
  • Directly in VS Code – provided by the Github Pull Requests and Issues extension

Source control github

Requirements

To get started, you need an active Github account. To create a new account, visit https://github.com to create an account.
c
Download and install VS Code on your device. Click here to get the latest version of VS Code.

Upon successful installation of VS Code on your device, install the “GitHub Pull Requests and Issues” extension on your Visual Studio Code


Setting up a Github repository

Now you have all the requirements ready.

You can create a new repository with the “+” icon on the top right navigation menu from any page on Github, and select “create a new repository”. The next page will look something like the screenshot below. Fill in the details and proceed.

github repository

Alternatively, if you’ll like to work on an existing project, find the project you’ll like to work on from the search menu, click to open, then locate “Code” on the top right section to view actions you can take on the project you have opened.

Github repository options

You can either;

  • Download as a zipped file
  • Open with GitHub desktop
  • Open with Visual Studio Code
  • Get direct HTTPS, SSH or CLI links.

Forking a project

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. It creates a copy of the project and saves it in your own profile.


Cloning your repository

Cloning a repository is easy. Firstly, you have to clone a repository that is hosted on Github.com. To create a new one, from your account, create a new repository, and let’s get started.

If you are looking to work on an existing project, you can search for and clone a repository from GitHub using the Git: Clone command in the Command Palette (Ctrl+Shift+P) or by using the Clone Repository button in the Source Control view (available when you are starting a new project and you have no folder open yet).

When you have a project running, the options are; to “initialize a repository” and “publish to GitHub”.

 


Someone you know might need this: Learn Data Analytics without any Tech Experience


GIT Commands and Codes;

Now that you understand how Git works, now take a look at the commands. The commands are run on Terminal or on the Command Prompt.

git config

Usage: git config –global user.name “[name]”

Usage: git config –global user.email “[email address]”

This command sets the author name and email address respectively to be used with your commits.

git init

Usage: git init [repository name]

This command is used to start a new repository.

git clone

Usage: git clone [url] 

This command is used to obtain a repository from an existing URL.

git add

Usage: git add [file] 

This command adds a file to the staging area.

Usage: git add * 

This command adds one or more to the staging area.

git commit

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

This command records or snapshots the file permanently in the version history.

Usage: git commit -a 

This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.

git diff

Usage: git diff 

This command shows the file differences which are not yet staged.

Usage: git diff –staged 

This command shows the differences between the files in the staging area and the latest version present.

Usage: git diff [first branch] [second branch] 

This command shows the differences between the two branches mentioned.

git reset

Usage: git reset [file] 

This command unstages the file, but it preserves the file contents.

Usage: git reset [commit] 

This command undoes all the commits after the specified commit and preserves the changes locally.

Usage: git reset –hard [commit]  This command discards all history and goes back to the specified commit.

git status

Usage: git status 

This command lists all the files that have to be committed.

git rm

Usage: git rm [file] 

This command deletes the file from your working directory and stages the deletion.

git log

Usage: git log 

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

Usage: git log –follow[file] 

This command lists version history for a file, including the renaming of files also.

git show

Usage: git show [commit] 

This command shows the metadata and content changes of the specified commit.

git tag

Usage: git tag [commitID] 

This command is used to give tags to the specified commit.

git branch

Usage: git branch 

This command lists all the local branches in the current repository.

Usage: git branch [branch name] 

This command creates a new branch.

Usage: git branch -d [branch name] 

This command deletes the feature branch.

git checkout

Usage: git checkout [branch name] 

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

Usage: git checkout -b [branch name] 

This command creates a new branch and also switches to it.

git merge

Usage: git merge [branch name] 

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

git remote

Usage: git remote add [variable name] [Remote Server Link] 

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

git push

Usage: git push [variable name] master 

This command sends the committed changes of master branch to your remote repository.

Usage: git push [variable name] [branch] 

This command sends the branch commits to your remote repository.

Usage: git push –all [variable name] 

This command pushes all branches to your remote repository.

Usage: git push [variable name] :[branch name] 

This command deletes a branch on your remote repository.

git pull

Usage: git pull [Repository Link] 

This command fetches and merges changes on the remote server to your working directory.

git stash

Usage: git stash save 

This command temporarily stores all the modified tracked files.

Usage: git stash pop 

This command restores the most recently stashed files.

Usage: git stash list  

This command lists all stashed changesets.

Usage: git stash drop  

This command discards the most recently stashed changeset.


GitHub Glossary – OTHER IMPORTANT TERMS

Access Token: A token that is used in place of a password when performing Git operations over HTTPS with Git on the command line or the API. Also called a personal access token.

Authentication Code: A code you’ll supply, in addition to your GitHub password, when signing in with 2FA via the browser. This code is either generated by an application or delivered to your phone via text message. Also called a “2FA authentication code.”

Branch: A branch is a parallel version of a repository. It is contained within the repository but does not affect the primary or main branch allowing you to work freely without disrupting the “live” version. When you’ve made the changes you want to make, you can merge your branch back into the main branch to publish your changes.

Checkout: You can use git checkout on the command line to create a new branch, change your current working branch to a different branch, or even to switch to a different version of a file from a different branch with git checkout [branchname] [path to file]. The “checkout” action updates all or part of the working tree with a tree object or blob from the object database, and updates the index and HEAD if the whole working tree is pointing to a new branch.

Code Owner

A person who is designated as an owner of a portion of a repository’s code. The code owner is automatically requested for review when someone opens a pull request (not in draft mode) that makes changes to the code the code owner owns.

Collaborator

A collaborator is a person with read and write access to a repository who has been invited to contribute by the repository owner.

Commit

A commit, or “revision”, is an individual change to a file (or set of files). When you make a commit to save your work, Git creates a unique ID (a.k.a. the “SHA” or “hash”) that allows you to keep record of the specific changes committed along with who made them and when. Commits usually contain a commit message which is a brief description of what changes were made.

Commit Author

The user who makes the commit.

Have you checked this out yet? It’s a good read;

Software development for beginners – Getting Started

Need more help on using Git and GitHub? Leave us a comment below!

Comments (0)

Leave a Reply