Alexa 101: Git and GitHub

So get ready and buckle up your seat belts, Sorry!! Sometimes Alexa loves cracking jokes. I mean you all might be ready with your PC and stable internet connection.

GitHub — Is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.

Git — This is a distributed version control system for tracking changes in any set of files, originally designed for coordinating work among programmers cooperating on source code during software development.

Version Control System — Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.

First, we have to visit this Website https://git-scm.com/downloads. And download Git according to your device. And then we have to complete the installation.

Local version control system — Maintains track of files within the local system. This approach is very common and simple. This type is also error-prone which means the chances of accidentally writing to the wrong file is higher.

Centralized Version Control Systems — Centralized version control systems contain just one repository and each user gets their own working copy where all team members are connected online. You need to commit to reflecting your changes in the repository. It is possible for others to see your changes by updating. If the internet connection is lost the changes are not saved before committing.

Distributed Version Control Systems: Distributed version control systems contain multiple repositories. Each user has their own repository and working copy. They commit changes and save the work to their “local repositories” This is because the commit will reflect those changes in their local repository and we need to push them in order to make them visible on the central repository. Similarly, When we update, we do not get other’s changes unless we have first pulled those changes into your repository.

Repository — It is the storage location for software packages and also known as “repo” in short form. A repo can be local or remote.

Local Repository — Repository stored in your local devices.

Remote Repository — Repository stored on your GitHub.

Commit — Using the “git commit” command we can save all the changes on the local repository.

Push — Upload Git commits that you have executed into a remote repository, for example to your GitHub account.

Pull — Download changes from a remote repository, for example, you are working on a project with your friend. He/she “pushed” the latest changes to the GitHub repository you are using for the project. You will need to pull those changes so that your local repository stays up-to-date.

Git Bash: Terminal-command line like platform allowing us to manage changes in our project by using a series of different commands (which will be discussed in the next post).

Let’s Create A Repository!

$ git --version
(Click on the “start” button, search for “Git Bash”. Click on it and execute the code written above.)
(Here you have to create a folder using the $ mkdir (make directory) command in your local device and after that using the $ cd(Change Directory) command change the directory into the folder you just created.)
$ pwd

pwd — pwd command is used to print the “Present working directory”

$ cd

cd — cd command is used for changing the directory.

$ cd ..

cd .. — refers to the directory immediately above the current directory, its parent directory.

$ mkdir <name of the folder/file>

mkdir — make directory allows you to create a new directory/folder.

Initializing Git

$ git init

For using Git, the installation will not be enough. We have to initialize and need to do some configuration. Configuration setting just for once, After that Git, will store and will use it when necessary. To initialize Git in our folder we need to use the following command.

(The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.)

See it's this simple! Now that we initialized, let’s move ahead and do the configurations.

$ git config --global user.name "your_GitHub_username"
$ git config --global user.email "your_GitHub_email"
(Now, go to GitHub browser and click on the “+” and then on “New Repository)
(Give your Repository a unique name, And click on “Create repository”)
(You will be directed to this “Quick setup page” now copy that link)
(Now paste the copied link after $git remote origin, “$git remote origin” command will automatically create a remote connection called origin for the folder we created. After that we will check the “$ git status” to check the state of the working directory.)
$ git remote origin <the link that you copied from remote repository>$ git status
(Now we will add helloo.txt file in the folder that we created on the local device.)
(And now when we use the “$git status” command we can see a change in our local device, but this may not appear on our remote repository for now what we have to do is use “$git add .” and then all the changes will be added and after that, we will use “$git commit” to save changes on local repository)
$ git add .
$ git commit -m <"Any message">
(The last step, we will use “$git push origin master” to push all the changes to the remote repository)
$ git push origin master
(Now what you can see is the helloo.txt file that you created on the local device is now present in the remote repository)

We will let some important Topics continue in the next Blog:

  • Going back to older versions,
  • Branching & merging,
  • Pushing & Pulling changes to our repository,
  • Cloning some other Repository.

--

--