How to push code to GitHub??

How to push code to GitHub??

Hey guys, if you want to learn how to push code on GitHub in easy way, then you are at right place. But before that you must have prior knowledge of Git and GitHub. I have written article on What is GitHub, if you want to learn about that then you can read my article.

So, without wasting any time, let's start our journey.

Step-1: Login to GitHub

Step-2: In the profile section, you will see '+' button, press that button

image.png

Step-3: Click on 'New repository' to create new repository image.png

Step-4: Now enter the repo name, if you want to add some description also, you can add that but that is optional. Leave all the things as it is and click on 'Create repository'

image.png

Step-5: After creating the repository, you will see the below page, that means you have successfully created the repository, wooh!!

image.png

Step-6: Now, open your folder where your code or file is present which is to be push on GitHub. I have currently only one file to push, you can have many

image.png

Step-7: Open you cmd/git/hyper or any other terminal which you have in this folder and type

git init

you will see this

image.png

Step-8: Now you have to link your folder to the GitHub repo you have made, so copy paste the one line on the terminal and hit enter, in my case it is

git remote add origin https://github.com/anubhav14g/sample-github-repo.git

remember, this below page when you have created the repository. In this page you will see above written line

image.png

Here 'github.com/anubhav14g/sample-github-repo.git' after origin word in above written line is the location of your GitHub repo

Step-9: So till now, you have linked your folder to the GitHub remote repo, that's awesome. Now you have to push the file, write below line on the terminal to add all files present in the folder to push on GitHub.

git add .

Step-10: We have added the files but before pushing them, we have to commit means have to add checkpoint/savepoint/lastpoint, so write below line on the terminal and hit enter

git commit -m "first commit"

Step-11: After committing the files, we have only one task left that is to push the files on GitHub remote repo, so let's do it by writing the below the line on the terminal

git push origin master

Step-12: So we have pushed the code also, now refresh the below page image.png

You code is pushed now and you will see that

image.png

Great!! that's all, we have pushed our first project to GitHub, that's awesome

Some Important points to Note:

  1. Initially, when we were creating the repo, you have seen the two options i.e private and public. We have chosen by default public but you can make your repo private also. By making repo private, no one can see your repo and in public, users can see your repo.
  2. There is one README.md file which you can create in your folder. This file basically tells about your project and you can write anything about you project in this file. After creating this file, you can push this file also to GitHub.
  3. There is another special file called, .gitignore file. This file is very important in GitHub, suppose you have some some file which contains sensitive information and you don't want to push that file on GitHub, so you can add that file in .gitignore file to prevent it to be pushed.

I hope you liked this article and enjoyed the journey.

Did you find this article valuable?

Support Anubhav Goyal's Blog by becoming a sponsor. Any amount is appreciated!