Git - Online Repositories

Advertisements


GitHub is a web-based hosting service for software development projects that use the Git revision control system. It also has their standard GUI application available for download (Windows, Mac, GNU/ Linux) directly from the service's website. But in this session, we will see only CLI part.

Create GitHub repository

Go to github.com. If you have already GitHub account, then login using that account or create new one. Follow the steps from github.com website to create new repository.

Push operation

Tom decides to use GitHub server. To start new project, he creates a new directory and one file inside that.

[tom@CentOS]$ mkdir github_repo

[tom@CentOS]$ cd github_repo/

[tom@CentOS]$ vi hello.c

[tom@CentOS]$ make hello
cc hello.c -o hello

[tom@CentOS]$ ./hello

Above command will produce the following result:

Hello, World !!!

After verifying his code, he initialized directory with git init command and commits his changes locally.

[tom@CentOS]$ git init
Initialized empty Git repository in /home/tom/github_repo/.git/

[tom@CentOS]$ git status -s
?? hello
?? hello.c

[tom@CentOS]$ git add hello.c

[tom@CentOS]$ git status -s
A hello.c
?? hello

[tom@CentOS]$ git commit -m 'Initial commit'

After that he adds GitHub repository URL as a remote origin and pushes his changes to the remote repository.

Note: We already discussed all these steps in chapter 4 under create bare repository section.
[tom@CentOS]$ git remote add origin https://github.com/kangralkar/testing_repo.git

[tom@CentOS]$ git push -u origin master

Push operation will ask for GitHub user name and password. After successful authentication, operation will succeed.

Above command will produce the following result:

Username for 'https://github.com': kangralkar
Password for 'https://kangralkar@github.com': 
Counting objects: 3, done.
Writing objects: 100% (3/3), 214 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/kangralkar/test_repo.git
 * [new branch]      master −> master
 Branch master set up to track remote branch master from origin.

From now, Tom can push any changes to the GitHub repository. He can use all the commands discussed in this chapter with GitHub repository.

Pull operation

Tom successfully pushed all his changes to the GitHub repository. Now, other developers can view these changes by performing clone operation or updating their local repository.

Jerry creates new directory in his home directory and clones GitHub repository by using git clone command.

[jerry@CentOS]$ pwd
/home/jerry

[jerry@CentOS]$ mkdir jerry_repo

[jerry@CentOS]$ git clone https://github.com/kangralkar/test_repo.git

Above command produces the following result:

Cloning into 'test_repo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.

He verified directory contents by executing ls command.

[jerry@CentOS]$ ls
test_repo

[jerry@CentOS]$ ls test_repo/
hello.c


Advertisements
Advertisements