Setting up a GitHub Repository and Basic commands

Step by step guide to set up a GITHub repository and GitBash commands.

What is GitHub(/GitBucket/BitBucket etc.. ) :

They are all also know as Source Code Management systems. We can store, track our code, collaborate on projects etc. We can access our code from anywhere in the world.

Step 1 : Create a GitHub account

Navigate to : https://github.com/ and Sign up. The Sign up UI looks really cool!

Fill in the information and click on Continue to proceed. GitHub will ask for email verification code sent to your email provided.

You can read for more information on their official documentation : https://docs.github.com/en/get-started/start-your-journey/creating-an-account-on-github

Step 2 : Create a repository :

On the Dashboard -> Go to Repositories tab -> Click on New :

Provide a Repository name, it should be unique. You can select Public/Private as per your preference. Then click on Create Repository button below.

GitHub will display set of commands to be executed at your local end. Before that, let's download Git on your system. It will come with Git Bash and Git GUI.

Step 3 : Download Git :

Navigate to : https://git-scm.com/downloads Click on the link according to your OS. Install the app and we are all set!

Step 4 : Open Git Bash in project folder :

Go to your project folder on your system. Right click, and you will able to see the Git Bash and Git GUI options. Select Git Bash :

Step 5 : Committing code to Git Repo :

Now, let's go back to our GitHub repository and complete set up :

We need to run the above commands on our Git Bash. README.md is optional. It is not mandatory to add this file at this stage.

  1. Run the first command "git init" in Git Bash. It is an one-time command which initializes our project repo at local system. It adds the .git subdirectory and creates the default "master" branch.

  2. Run "git status" (optional) : It will show all the changed files need to be staged for commit. (in red)

  3. Run "git branch" (optional) : It should display "master".

  4. Run "git add ." : The files are staged to be committed.

  5. Run "git status" (optional): It show all files (in green) that are staged to be committed.

  6. Run "git commit -m "some comment about the commit" " : Files are committed.

  7. Run "git status" (optional) : It should show following message :

     $ git status
     On branch master
     Your branch is ahead of 'origin/master' by 1 commit.
       (use "git push" to publish your local commits)
    
     nothing to commit, working tree clean
    
  8. Run "git remote add origin github.com/debasmita-a/test-repo.git" : It basically makes the connection to the remote repository (where to push the code). It is an one-time command to run.

  9. Run "git push -u origin master" : It will push the code to the remote repository. Refresh the page on GitHub and the code should be available with commit ID.

There are a lot of other actions and commands that will be used in day-to-day project activities. The above are some basic git commands. Let's see couple of other commands :

  1. git clone repositoryURL : Run this command in your workspace folder. It will clone the already available remote repository from GitHub.

  2. git pull : This will pull updated code changes to the project directory.