Git and GitHub for Beginners III(Tutorial)

PJ Wang
CS Note
Published in
7 min readNov 17, 2017

What is GitHub?

GitHub is a Web-based Git version control repository hosting service. It is mostly used for computer code. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.

GitHub offers both plans for private and free repositories on the same account which are commonly used to host open-source software projects. As of April 2017, GitHub reports having almost 20 million users and 57 million repositories, making it the largest host of source code in the world. GitHub has a mascot called Octocat, a cat with five tentacles and a human-like face.

GitHub

Step 1: Sign up for GitHub

Go to the website: https://github.com/ , and click Sign up for GitHub .

Step 2: Create a repository

After sign up, we could sign in and create a repository.

And set your repository name and privacy.

Enter your repository.

Step 3: Create a new branch

We create a new branch named debugger.

Click the file ReadME.md , and edit it.

Add any words you want for testing.

Scroll down and insert the description for this update.

We compare with two branches.

Step 4: How to pull request?

Two branch need to pull and merge, and do the following step.

4–1 Go back to debugger branch, and click New pull request .

Go to the new page.

After click Create pull request .

Back to master branch, and you will see the Pull requests 1 .

Click Pull requests , and show the following page.

Click Update README.md , and Merge pull request.

Confirm merge.

It will show the successful page.

Step 5: Clone it to local

Copy the GitHub url.

New a file named GitHub and initial it.

Clone the repository.

GitHub user$ git clone 'put your url here'

Look over the status.

You could operate your repository after cd MyRepository .

GitHub user$ cd MyRepository
MyRepository user$ git status

Step 6: Update your file

How to add and commit the file? Review Git and GitHub for Beginners I(Tutorial).

MyRepository user$ touch NewFile
MyRepository user$ git add NewFile
MyRepository user$ git commit -m "Add NewFile"

After commit, push your file to GitHub. git push <repository name> <remote branch name>

MyRepository user$ git push origin master

Step 7: Pull request every time before the file is modified.

Next time, If you want to add or modify the file, you need to pull request first. And it will be a newest version on the GitHub.

MyRepository user$ git pull origin master

Summary

GitHub user$ git init# Use clone at first time.
GitHub user$ git clone https://github.com/daniel820710/MyRepository.git
gitDemo user$ cd MyRepository
# Start from here to modify the file every time.
MyRepository user$ git pull origin master
MyRepository user$ touch NewFile
MyRepository user$ git add NewFile
MyRepository user$ git commit -m "Add NewFile"
MyRepository user$ git push origin master

How to use basic command?

Git and GitHub for Beginners I(Tutorial)

How to use branch?

Git and GitHub for Beginners II(Tutorial)

Appendix

Git push

Look over the branch, and just only masterbranch.

And you could use git branch -a to show the remote branch.

Upload local branch. Use git push <remote name> <branch name>

MyRepository user$ git push origin master

If you also want to track it, use git branch -u <remote name> <branch name> or git branch --set-upstream <remote name> <branch name>

MyRepository user$ vim README.md
MyRepository user$ git add README.md
MyRepository user$ git commit -m "local branch"
MyRepository user$ git push -u origin master

After using push -u , use push will push master to origin automatically.

MyRepository user$ git push

Git branch

We create the new branch debuggeron local. (The local branch name must be identical with remote branch name)

MyRepository user$ git branch -a

We add and commit the new file, after that, we push it to remote branch

MyRepository user$ git checkout debugger
MyRepository user$ touch debuggerFile
MyRepository user$ git add debuggerFile
MyRepository user$ git commit -m "Add debuggerFile"
MyRepository user$ git push origin debugger

And we could track the version of different between local branch and remote branch.

MyRepository user$ git branch -u origin/debugger

If we modify the file on local branch, and look over

And if we go back to previous version HEAD^^^

We use git pull to update to newest version. And cancel to track use --unset-upstream .

MyRepository user$ git branch --unset-upstream

How to delete remote branch? use $ git push -d <remote_name> <branch_name>

MyRepository user$ git push -d origin debugger

GitHub use fork

We could copy repository belongs to the other user. Go to the user’s repository you want to copy and press fork .

It will copy to your repository.

If the file will update in original repository, you could use Pull request to update.

Press New pull request .

Click switching the base .

And click Create pull request .

Insert the comment and press Create pull request .

Press the Merge pull request and confirm merge .

Successful.

--

--

PJ Wang
CS Note

台大資工所碩畢 / 設計思考教練 / 系統思考顧問 / 資料科學家 / 新創 / 科技 + 商業 + 使用者