ghostbody / 15-cpp-learning

15 c++ learning repository of SDCS SYSU
6 stars 3 forks source link

Git Basic Tutorial #5

Open ghostbody opened 8 years ago

ghostbody commented 8 years ago

1. What is Git?

Git is a version control software which is created by Linus who also created linux.In computer software engineering, revision control is any kind of practice that tracks and provides control over changes to source code. Software developers sometimes use revision control software to maintain documentation and configuration files as well as source code. Other version control software includes: VSS-- Visual Source Safe provided by Microsoft SVN-- CollabNet Subversion provided by CollabNet GIT-- Linus Torvald in order to mange the kernel version of linux at the very first time.

image Version Control System

2. What is github?

Github is an open source community who has so many open source repository in it. People can work together in github, upload their code and also write documentations. You can happily work with people all over the world if you like. Also, there is also GitLab, GitBook, GitCoffee and GitOS.

3. Git and github?

Git is a version control software while github is a code hosting system using git as its version control system. Also github provides other functions like issues, wiki and git pages.

4. How to install git?

I recommend you to use command line git rather than a graphic one. In linux, you can just:

sudo apt-get install git

In windows, you are required to download git bash.

For graphic version, you can download github desktop. But I think it's not good enough for me, because it has some bugs I wonder.... Or command line is better, I think.

5. How to create and then update my code?

First, go to github to create a repository in your home page. Then github will give you some hint to initialize you repository. Generally:

Before this, you are required to config your username and email locally.

git config --global user.username "your username"
git config --global user.email "your email"

And also, you need to config your ssh key before you can upload you repository. In linux:

ssh-keygen

Input according to the hint of the program. You may just skip the inputs.

cd ~/.ssh
cat id_rsa.pub 

image

You will get a random string.

Go to setting: image

image

Add your new key here using the random string you get.

image

Optionally, you can choose HTTPS as your transfer protocol, but you have to input username and password for each time when you need to modify remote repository.

git clone $YOUR_RES

If you have a local work repository, you can:

git init
git remote add origin $YOUR_RES
``

If you want to update the code, you need to:
```shell
git add .
git commit -m "yuo comment for this commit"
git push origin master

Look this is the workflow for you github work.

image

6. How to establish a collaboration with other persons?

There will be two ways: The first one, add a "collaborator". Enter you project setting page.

image

Click Collaborator: image

Then you can invite user to your project and he will get all rights you have in the repository and he can update code himself.

The Second way is the same as contributing code for other open source repository.

6. How to contribute to other open source repository while I am not a collaborator?

First, fork the repository to your own space. image

Then you can regard it as your own repository, and the coding with it using step 5. When you update the code(add new features or fix bugs or optimize the algorithm).

At last, you should make a "pull request" to the master of this repository. The system will auto compare your branch with the master's branch. Then, you can leave a comment and the code will submit to the master.

After some time, the master will accept your code, say "merge your pull request" or reject your code, maybe with some comments. If the owner or collaborators reject you code, he may comment on you commit with "blames".

image

Also, you can use this way for collaboration project which can protect the repository well.

image pull request merged

7. Resolving conflicts.

One annoying thing is github is conflict.If the two branches you‘re trying to merge both changed the same part of the same file, Git won’t be able to figure out which version to use. When such a situation occurs, it stops right before the merge commit so that you can resolve the conflicts manually.

First, when you are in collaboration with others, you should always run git pull or git fectch before you commit you code. And also, you should not modify your teammates' part of code.

If a conflict occurs, you must resolve it in this condition. The great part of Git's merging process is that it uses the familiar edit/stage/commit workflow to resolve merge conflicts.

Then, you can go in and fix up the merge to your liking. When you're ready to finish the merge, all you have to do is run git add on the conflicted file(s) to tell Git they're resolved. Then, you run a normal git commit to generate the merge commit. It’s the exact same process as committing an ordinary snapshot, which means it’s easy for normal developers to manage their own merges.

Note that merge conflicts will only occur in the event of a 3-way merge. It’s not possible to have conflicting changes in a fast-forward merge.

image conflicts resolving is very annoying

8. Branches.

A branch, at its core, is a unique series of code changes with a unique name. Each repository can have one or more branches. In Git, branches are a part of your everyday development process. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes. This makes sure that unstable code is never committed to the main code base, and it gives you the chance to clean up your feature’s history before merging it into the main branch.

image

By default, the first branch is called "master".

Prior to creating new branches, we want to see all the branches that exist. We can view all existing branches by typing the following:

git branch -a

As stated in the beginning of this article, we want to have a development and a production setup for our coding environment.

We are going to treat the default "master" branch as our production and therefore need to create a single branch for development, or pre-production.

To create a new branch, named list-in-cpp in the repository "15-cpp-learning", type the following:

git checkout -b list-in-cpp

Use this command to switch back to master.

git checkout master

branches can make our collaboration job more clear: This is an overview of our open source desktop robot "Mebot"

image

You can also merge two branches as you like.

image

9. Issues, release, wiki and etc.

image

Code; The files of you repository

Issues: Some bug report, problems discussion can be placed here, while some people use it to write blogs, hhhhh.

image

Wiki: This is a place for you to have documentations and also some knowledge for you repository. You can make use of it.

Pulse and Graph is mainly some information about your repository including contribution information.

10. Using Markdown

You are required to learn some knowledge about markdown which is the main documentation language in github. You can focus on the content of you text rather than formats using a few symbols. You can have pretty formats, too.

Styling with Markdown is supported

11. Git pages

You can use git pages for you project description or for your personal blog. It's very easy to make it. Just create a repository named "your-user-name.github.io". And then upload htmls to the repository and then you can access the website "https://your-username.github.io".

If you want to use some more fashion way, I recommend you to use Jeklly which is a static blog tool written in Ruby. And github use this software to build you git pages. And also you can run your static anywhere outside github using Jeklly Server.

My github page blog

12. More

Interesting links:Git tutorial

Discuss here if you have any questions

KatharinaLin commented 8 years ago

Sorry I look up on the Internet and PPT but still can't undestand this picture. 16 04 15 2202_1

KatharinaLin commented 8 years ago

what is Arithmeic and its properties?

ghostbody commented 8 years ago

They are template instances. Think about when you make an instance for a class. They are just two specifications from a more abstract class template.