- Git - Home
- Git - Version Control
- Git - Basic Concepts
- Git - Command Line
- Git - Installation
- Git - First Time Setup
- Git - Basic Commands
- Git - Getting Help
- Git - Tools
- Git - Cheat Sheet
- Git - Terminology
- Git - Life Cycle
- Git - Get a Repository
- Git - Adding New Files
- Git - Recording Changes
- Git - Viewing Commit History
- Git Branching
- Git - Branches in a Nutshell
- Git - Creating a New Branch
- Git - Switching Branches
- Git - Branching and Merging
- Git - Merge Conflicts
- Git - Managing Branches
- Git - Branching Workflows
- Git - Remote Branches
- Git - Tracking Branches
- Git - Rebasing
- Git - Rebase vs. Merge
- Git - Squash Commits
- Git Operations
- Git - Clone Operation
- Git - Tagging Operation
- Git - Aliases Operation
- Git - Commit Operation
- Git - Stash Operation
- Git - Move Operation
- Git - Rename Operation
- Git - Push Operation
- Git - Pull Operation
- Git - Fork Operation
- Git - Patch Operation
- Git - Diff Operation
- Git - Status Operation
- Git - Log Operation
- Git - Head Operation
- Git - Origin Master
- Git Undoing
- Git - Undoing Changes
- Git - Checkout
- Git - Revert
- Git - Reset
- Git - Restore Operation
- Git - Rm
- Git - Switch Operation
- Git - Cherry-pick
- Git - Amend
- Git on the Server
- Git - Local Protocol
- Git - Smart HTTP Protocol
- Git - Dumb HTTP Protocol
- Git - The SSH Protocol
- Git - The Git Protocol
- Git - Getting Git on a Server
- Git - Setting up the Server
- Git - Daemon
- Git - GitWeb
- Git - GitLab
- Git - Third Party Hosted Options
- Distributed Git
- Git - Distributed Workflows
- Git - Contributing to a Project
- Git - Maintaining a Project
- Customizing Git
- Git - Configuration
- Git - Hooks
- Git - Attributes
- Git - Init
- Git - Commit
Git - Online Repositories
GitHub is a web-based hosting service for software development projects that uses 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 already have the GitHub account, then login using that account or create a new one. Follow the steps from github.com website to create a new repository.
Push Operation
Tom decides to use the GitHub server. To start a 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
The above command will produce the following result:
Hello, World !!!
After verifying his code, he initializes the directory with the 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 the GitHub repository URL as a remote origin and pushes his changes to the remote repository.
[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, the operation will succeed.
The 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 the 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 a new directory in his home directory and clones the GitHub repository by using the git clone command.
[jerry@CentOS]$ pwd /home/jerry [jerry@CentOS]$ mkdir jerry_repo [jerry@CentOS]$ git clone https://github.com/kangralkar/test_repo.git
The 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 verifies the directory contents by executing the ls command.
[jerry@CentOS]$ ls test_repo [jerry@CentOS]$ ls test_repo/ hello.c