Push your first commit to Github

An introduction to version control using Git and Github

·

2 min read

Creating a Github repository

rubaitul-azad-HLQDfaJUTVI-unsplash.jpg This tutorial assumes you have Git installed in your system. Download it from here

Sign in to Github

Create a repository called first-commit.

createrepo.PNG Scroll down and click on create to create the repository

Your next screen be similar to:

createrepo2.PNG

Create a folder

On your desktop called first-commit. Open the folder in a terminal. You can use either right-click and select Git Bash or type cmd on the address bar and press enter. It opens the windows command prompt.

openinterminal.PNG

#. Initialize repository: Initialize an empty git repository using

git init

gitinit.PNG

Add url:

Copy the repository URL from the address bar of your browser image.png

Add remote origin:

git remote add origin <repo_url>

Replace with the URL you copied in the previous step.

image.png Note the .git we added at the end of the URL

Check to make sure the URL has been successfully added. Use the command below:

git config --get remote.origin.url

Your output should be similar to:

image.png

Create a file.

Create a simple text file in the first commit folder we created in the previous step.

image.png

Committing the file.

Switch to your terminal and check for changes using the command:

git status

image.png

Commit the file.

  • Stage the changes (the file created) using:

    git add text.txt
    

    To stage all change, use:

    git add .
    
  • Commit the changes using the command

    git commit -m "my first commit"
    

    -m is the message flag and the value is my first commit

Your output should be similar to:

image.png

Push the changes.

Upload the changes to your remote repository. Push the changes using the git command:

git push --set-upstream origin master

Here, master is my the branch am pushing to. You can check the branch you are working on using git branch

Your output should be similar to:

image.png

Refresh the page on your browser.

image.png

We have successfully pushed our first commit to Github.

Tell us what you think in the comment section.

Â