Google Code-In 2016

                        INTRODUCTION TO GITHUB


This blog will help you to push your project on github. Make your project open-source to introduce it to the world. Managing different versions of your project will become quite handy.

In this we will start with an introduction to git and then see some basics command to push the project .

What is Git ?

Git is an open source and free version control system which helps you to manage different version of a project effectively and quite efficiently.

It is used for software development and other version control tasks. It was created by Linus Torvalds in 2005.

 Git Push: Pushing refers to upload your project onto a server such as github.com here. So that others will use your code and can fork too.

Step 1: Installing Git in your system.

 

 

This is the page which shows the command-line to install git in different operating systems.

For windows you have to download .exe file and install it.

 

I am using Ubuntu 16.04 here.

 

Type sudo apt-get install git to install git in your system.

Step 2: Now its time to create an id on github.com .

We need an id on git to deploy our projects on that Github account.

After you successfully log in then you will be welcomed by such screen.

Step 3: Click on the ‘+’ sign on the top right to create a new repository.

Repository: A repository is simply a folder which contains all of the files and data of your source project.

After you create your repository, you will see a page like this:

Step 4: On your computer, go to your directory using the terminal, using the linux command line you would cd into the directory. 

From here you run the following commands to “connect” your existing project to your repository on github.

 Step 5: First do this to initialize git (version control).

git init

This command will create an empty git repository. This is mostly the first command you will have to run to make available all the other commands. Initalization is must to make git request to successfully execute the rest of the commands. 

Suppose if we don’t initalize the folder which we have to commit then push, then its impossible for git add to data the files which is to be committed. 

This will initializes a git repository – creates the initial ‘.git’ directory in a new or in an existing project.

Example: cd /home/user/Desktop/version_control/git

Note:  The .git directory – It is a hidden directory which contains some files used to run the commands. We basically don’t have to tense about this folder.

Step 6: Then do this to add all your files to be “monitored.”

git add .

This command will adds files changes in your working directory to your index, so that it get added and from now it will be part of the project. It will add the changes to the working directory. It would not affect till you made the next commit and at the time of commit the file will get updated which you add up before. 

Step 7: Then you commit and add a note in between the “”

git commit -m "Initial Commit"

Commit –“commit” is a snapshot of our repository. Snapshot refers to different versions of the project or the file.

Git commit refers to the changes which you made in your project and you have provided that type of change a name, so that in future if you need to roll back, you can easily do it. Committing is as important as git add since the update wouldn’t be there if the commit hasn’t been made. As in the snapshot it can been seen that it also shows the the files which are committed, it is the same files which are add by us.

If we don’t use git commit, the changes we made will not be saved which we further going to push.

Step 8:Now copy your git repository address

Step 9: Now, here is where you have to add  your repository git remote add github  

Note: which i asked you to copy then command is:

git remote add github https://github.com/meets2tushar/my_webpage.git

You will asked here to enter your github username and password. This is required so that no other person could made changes to your repository without your permission

It may happened that you have to execute this command more than once (as in my case) . This could happen due to lost in connection or may be failure of the server. 

 git remote add: This command will help you to add your project to the particular repository which you created on github. The url used is the address of the repository in which you want the changes to be made. Thus after executing this command the changes are become ready to push to the repository.

Initially we have to provide the url to let the git know that where to the data.

Step 10: Test to see that it worked by doing

git remote -v

It will list all currently configured remote repositories. We can see from the image that the url where our repository is and is being ready to push.

Step 11: Now its time to push changes to github.

git push -u origin master

 It will push the local repository to the github account and make it completely online and open-source. Thus the last command which actually upload or update the changes made in our project.

Now refresh the github page to view the changes.

screenshot-from-2016-12-06-23-00-56

We can see now that what we have add and then commit are push to the repository address which we add add using git remote add.

So each command has its own importance and they must be executed in a sequence as mention. 

Thank You

I hope you like this blog,

comment your important feedback.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: