How to Initialize and Configure Git:

(On Windows Operating System)

How to Initialize and Configure Git:

Hi fellow readers,

In this blog, I'll be explaining one of the many ways to initialize and configure Git in your computer (with a Windows Operating System) to get started with GitHub and its features.

Prerequisites for installing Git to your computer:

  • Have a GitHub account.

  • Having made a Repository.

  • Terminal (Command Prompt in Windows).

  • Git Bash (Can be downloaded and installed from here).

Step 1:

Open Git Bash Git bash.jpg Git bash 2.jpg

Step 2:

Make a Git directory (folder) in your desired drive. git folder location.jpg

Now we have to get into the folder through git bash: For that we are going to use the Change Directory 'cd' command in Git Bash.

  • To get into the drive that has the git folder
    cd /c
    
  • To get into the git folder
    cd git
    
  • To list out the files inside the folder
    ls
    
    Since there is nothing inside the folder, no outputs are displayed.

Step 3:

We need to configure our GitHub account to Git Bash:

git config --global user.name "<yourname>"
git config --global user.email <youremail>

config.jpg

Step 4:

Cloning the GitHub repository in the Git directory:

A repository should be created on GitHub in order to clone it. We can easily create a repository in GitHub by clicking Your Repositories > New.

After creating the repository with a recognizable name, we need to copy the .git link of the repository in order to execute the cloning process in Git Bash: link.jpg

git clone https://github.com/accountname/repositoryname.git

clone.jpg

The repository is cloned to the computer and can be seen inside the Git directory.

repo.jpg

Step 5:

Now we need to push a file to our Repository in our GitHub account:

  • For that, we'll make a text file inside the repository folder and we'll push that file to GitHub.

test.jpg

The following commands will be used to push the file:

  • To get into the repository folder.
    cd TestGit
    
  • To list out the files.
    ls
    
  • To initialize Git repository.
    git init
    
  • To add the file in Git.
    git add <filename>
    
  • To check status of the newly added file and existing files(if any).
    git status
    
  • To input a commit message along with the file added into git.
    git commit -m "commit message"
    
  • To push the file to the GitHub account.
    git push -u origin main/master
    

gitadd.jpg

Step 6:

The file has been pushed to the GitHub account and the GitHub page needs to be refreshed to see the uploaded file.

account.jpg

Step 5 can be done with other text editor applications having a terminal like Visual Studio Code, the .c extension file needs to be saved in the repository folder to get pushed to the GitHub account.

And that's how Git is configured into the PC and files can be pushed to GitHub through GitBash or any other terminal.

Hope you find this blog useful and don't forget to leave your valuable feedback.

Thank you for reading!