Getting started with Git and Github
Tags: hackclub, hackclubcgc, git, github
Published: 2020-08-18 09:57:36

When I started with git and GitHub, it was a real pain. Most of the tutorials were terrible, I mean really terrible.
I want this article **not** to be a tutorial but my experience on how I figured it all and you can too.
So, first of all, you may be thinking what the heck is git?
In technical terms, you can call it "version control system".It means it creates a record of every change in our files. It was developed by Linus Torvalds(Yeah, you guessed right, he is the creator of Linux kernel too!). Its popularity can mostly be attributed to Github, the most popular open-source hosting and management system which provides git version control functionality.

##Installing git

###Windows
To download git for windows, visit [https://git-scm.com/download/win](https://git-scm.com/download/win). The downloading will start automatically.

With git installed, what to do now?
Go to cmd and type 

    git --version 

to make sure git is installed properly.

##Working with git

With git installed, we should now head to [Github](www.github.com). Create an account.

Github stores codebase in what they call repository. We are going to create one.
Click on the new button to create the repo. We will be working with this repo.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fpwuw4rt6alan0f5na3f.jpg)
Fill the details and ta-da you have created your first Github repo.
Open your repo and click on the code button and copy the URL.

####Spoiler! 
The coming steps are Command interface intensive.
If you are GUI type, then be sure to check out the GitHub desktop app. 

For the command interface, I would recommend using git bash. It comes with git installation.

If you want to work with others repo, firstly Fork(github term for copy) the repo. This can be done easily from the fork button on the repo's page.
Follow the below given steps for further workflow.

Okay, let's continue with our repo.
Our first step would be to copy the repo to our local machine. It is done like this,

    git clone [your GitHub repo url]

This will copy the repo to your local machine. Url can be of forked repo or newly created repo.
Now make some changes to your code in your favorite editor.
In git bash type

    git add .

This will add your file to the staging area(sort of temporary storage)
then type

    git commit - m "Your commit message"

This is to tell others what changes you have made.
finally, type

    git push origin master

This command will push the changes to your Github repo.
Last but not least let's list the steps for pushing your local changes to the remote repository.

    git add .

    git commit -m "your commit message"

    git push origin master

If everything goes right, then your changes will be reflected in the remote repository.

###Creating and pushing local repo to Github.

Go to Github and create an empty repository.
In git bash, go to a suitable folder and type

    git init

This will initialize a git repo in your folder.
Type,

    git remote add origin [repo url]

Be sure to firstly, stage, and commit your changes. Then,

    git push -u origin master

Changes will be reflected in the Github repo.

There are some commands you should know,

    git status

This command lists all the modified files that are not staged and committed.

    git log

This command lists all the commits.

Before we wrap up, there another important concept,Branching.

#####Branch.

It is a very powerful and useful feature of git, for example, if you want to test a new feature without compromising the whole code, just create a branch. Changes you made in this branch will not affect the main 'master' branch and vice versa(When we create a Github repo, it automatically creates a 'master' branch, which is the default branch).

Creating a branch is easy

    git branch [branch_name]

To work on the branch, you need to go to the branch
just type

    git checkout -b [branch_name]

To merge the branch,

    git merge [branch_name]

Well, this is all you need for the starter pack.

Goodbye👋