GitHub example

In this example, we will use GitHub as the centralized location to synchronize our local repository and share with other users. 

We will create a repository on GitHub. By default, GitHub has a free public repository; in my case, I pay a small monthly fee to host private repositories. At the time of creation, you can choose to create the license and the .gitignore file: 

GitHub private repository

Once the repository is created, we can find the URL for this repository: 

GitHub repository URL

We will use this URL to create a remote target; we will name it gitHubRepo

$ git remote add gitHubRepo https://github.com/ericchou1/TestRepo.git
$ git remote -v
gitHubRepo https://github.com/ericchou1/TestRepo.git (fetch)
gitHubRepo https://github.com/ericchou1/TestRepo.git (push)

Since we chose to create a README.md and LICENSE file during creation, the remote repository and current repository are not the same. If we were to push local changes to the GitHub repository, we would receive the following error: 

$ git push gitHubRepo master
Username for 'https://github.com': [email protected]
Password for 'https://[email protected]@github.com':
To https://github.com/ericchou1/TestRepo.git
! [rejected] master -> master (fetch first)

We will go ahead and use git pull to get the new files from GitHub: 

$ git pull gitHubRepo master
Username for 'https://github.com': <username>
Password for 'https://<username>@github.com':
From https://github.com/ericchou1/TestRepo
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
.gitignore | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LICENSE | 21 +++++++++++++
README.md | 2 ++
3 files changed, 127 insertions(+)
create mode 100644 .gitignore
create mode 100644 LICENSE
create mode 100644 README.md

Now we will be able to push the contents over to GitHub:

$ git push gitHubRepo master
Username for 'https://github.com': <username>
Password for 'https://<username>@github.com':
Counting objects: 15, done.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (15/15), 1.51 KiB | 0 bytes/s, done.
Total 15 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/ericchou1/TestRepo.git
a001b81..0aa362a master -> master

We can verify the content of the GitHub repository on the web page: 

GitHub repository

Now another user can simply make a copy, or clone, of the repository: 

[This is operated from another host]
$ cd /tmp
$ git clone https://github.com/ericchou1/TestRepo.git
Cloning into 'TestRepo'...
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 20 (delta 2), reused 15 (delta 1), pack-reused 0
Unpacking objects: 100% (20/20), done.
$ cd TestRepo/
$ ls
LICENSE myFile.txt
README.md mySecondFile.txt

This copied repository will be the exact copy of my original repository, including all the commit history: 

$ git log
commit 0aa362a47782e7714ca946ba852f395083116ce5 (HEAD -> master, origin/master, origin/HEAD)
Merge: bc078a9 a001b81
Author: Eric Chou <[email protected]>
Date: Fri Jul 20 14:18:58 2018 -0700

Merge branch 'master' of https://github.com/ericchou1/TestRepo

commit a001b816bb75c63237cbc93067dffcc573c05aa2
Author: Eric Chou <[email protected]>
Date: Fri Jul 20 14:16:30 2018 -0700

Initial commit
...

I can also invite another person as a collaborator for the project under the repository setting: 

Repository invite

In the next example, we will see how we can fork a repository and perform a pull request for a repository that we do not maintain. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset