Configure Github On Your Device Easily - For Beginner

Configure Github On Your Device Easily - For Beginner | This post will show us how to configure our device for GitHub. We will Do it by making a demo project and then pushing it on GitHub. And then updating it after some changes were made to our Demo Project

0. Why do We Need Github?

GitHub is a platform made for developers or programmers where they can share, save, edit, collaborate, host their projects or codes, and many more kinds of stuff.
So this is a most-knowing platform for all developers and programmers.
In Github all the projects and files are saved inside a Folder which is Known as Repository.

1. Download Github SCM

First, we need to download Github SCM where SCM stands for Source Code Management. It is used to manage our local GitHub repository. Local GitHub repository is just your Project folder on your local machine.

From here it is clear that first, we create a folder on our local machine and then save it ( push it ) on our GitHub by making a repository ( folder ) there. We will see how to do this later in this Blog.

2. Installing Github SCM

Once we have downloaded Github SCM we need to install it.
Run the Downloaded file and just keep pressing the next button and then finally install button, leaving all the default fields selected.
Once the Git SCM is installed you can open your command terminal and type git –version. It will show you the GitHub version something like this git version 2.37.0.windows.1. This insures that your device is ready to work with git.

3. Creating a Local Github Repository ( Folder )

Now let’s create a Project on our device. So to create a Project first let’s create a folder where only the items related to our project are present. Let the name of our project folder be my_project_folder

Inside our Project Folder create a File, let it be first.txt, as you can see it’s just a text file. So open it with a notepad and insert some text inside it and save it. Now we have something to push to our GitHub. By Push I mean to send it to the GitHub repository. We will see soon how to do that.

Now let’s create a local GitHub repository using Github SCM which we installed earlier. To create a local GitHub repository open the command terminal in the project folder and type git init. It will create a .git file in your project folder. It might not be visible to you as it comes under a hidden file. To see .git file turn on the view > show > hidden items from the explorer menu, though we don’t need to see this as we are not going to edit this folder.

This local GitHub repository is very important as it will store all the changes you made in your project folder, so don’t change it manually or delete it until you know what you are doing.

4. Creating Git Repository on GitHub

Now lets go to Github to create a new repository on Github. If you don’t have an account then first create an account or log in to your account. Once you are logged in to your account then create the new Repository on GitHub from HERE

In the Repository name section type any name, for now, let’s use first_repo then select the private from the option and yes uncheck the create readme file option. Then click on Create Repository button.

This will redirect you to your brand new and first repository. You will see many commands, like:-
git init or git add README.md but for now let’s go and connect this GitHub Repository to our Local Repository (Folder)

5. Connecting GitHub Repository with the Local Repository

Now Both the Local And Github Cloud Repository are Ready. Let’s go to our Local Repository ( Folder ) and open the terminal in that folder. And First Set your username and email in terminal by running these two Commands.
git config –global user.name “YOUR_GITHUB_USERNAME” git config –global user.email “YOUR_GITHUB_EMAIL” This will configure your command line for our GitHub account.

Now in the Command terminal type the following one by one :

1
2
3
git add .
git commit -m "first commit"
git branch -M main

Now we need to tell our local repository where the remote GitHub repository is located. Go back to the GitHub page where you created the repository (first_repo). You should see a section titled “…or push an existing repository from the command line”. Copy the command that looks like this:

1
git remote add origin https://github.com/YOUR_GITHUB_USERNAME/first_repo.git

Replace YOUR_GITHUB_USERNAME with your actual GitHub username. Paste this command into your terminal (which should still be open in your my_project_folder) and press Enter. This command links your local repository to the remote one on GitHub, naming the remote connection ‘origin’.

Finally, push your local commit to the GitHub repository using this command:

1
git push -u origin main

This command pushes the ‘main’ branch from your local repository to the ‘origin’ remote (your GitHub repository). The -u flag sets the upstream tracking reference, so in the future, you can simply use git push and git pull.

You might be prompted to log in to GitHub via your terminal or a pop-up window. Once authenticated, your code will be uploaded. Refresh your GitHub repository page in the browser, and you should see your first.txt file there!

6. Making Changes and Pushing Updates

Now that your project is on GitHub, let’s see how to update it.

  1. Make a change: Open the first.txt file in your my_project_folder and add some more text. Save the file.
  2. Stage the changes: Go back to your terminal (still in the project folder) and type:
    1
    
    git add .
    
    This command stages all modified files (in this case, just first.txt).
  3. Commit the changes: Commit the staged changes with a descriptive message:
    1
    
    git commit -m "Updated first.txt with more text"
    
  4. Push the changes: Push the new commit to GitHub:
    1
    
    git push
    
    (Notice we don’t need -u origin main this time because we set the upstream tracking earlier).

Refresh your GitHub repository page again, and you’ll see the updated content in first.txt.

7. Conclusion

Congratulations! You’ve successfully configured Git on your device, created both local and remote GitHub repositories, connected them, and pushed your first project (and an update!) to GitHub.

This is the basic workflow most developers use daily. GitHub offers many more features like branching, merging, pull requests for collaboration, and hosting static websites via GitHub Pages, but this foundation is crucial. Keep practicing, and explore the vast possibilities GitHub offers!