Getting started with Github, easy to use!


Explanation: I also started using github recently due to development needs. At first, I didn't understand what it was, but I only knew that it was a very useful thing! This blog is like talking about my understanding of github and how I understand it.

System environment: Linux Mint 15 64-bit operating system

1 : What is github?
Git is a distributed version control system originally written by Linus Torvalds for the management of Linux kernel code. After its launch, Git has seen a lot of success in other projects, especially in the Ruby community. Currently, many well-known projects including Rubinius and Merb use Git. Git can also be used by deployment tools such as Capistrano and Vlad the Deployer.
github can manage your code very well, don't worry about accidentally making a mistake or losing it! 2: Only one code is required to install git under ubuntu and mint
on github

   
$sudo apt-get install git

After installation is complete. We can look at Git's books
    cuitmnc@cuitmnc ~ $ git --version
    git version 1.8.1.2

This is my git book, the version may be different due to the different installation time!
Three: The use of git
3.1 First, we need to register a Github account.
Address: https://github.com/
Click Sign Up to fill in your registration information! After successful registration, verify your email address to complete the registration!
3.2 Create a repository on the remote side

Click New repository, and

after entering the repository name, click Create repository! You can create a successful version library!
Note: private repositories require payment! So generally we will create it in the form of publice!
After the creation is successful, the following screen will appear. The name of the repository I created here is testgit

3.3 Submit the code to the remote (created repository)
locally, and a project folder where I store the code is testgit
First, we need to enter testgit folder
cd ~ / testgit

After entering the folder, we use the command
git init

After initializing our code folder
successfully , you will be prompted
Initialized empty Git repository in /home/minchina/testgit/.git/
touch README.md

Create a README.md file, the content of which will be displayed on our repository page content! Generally, it is the description and usage of our project!
git add .

Tell us that all files are added to the cache to be submitted, and this can also be done here
git add filename


Commit a file alone, provided we know we've only modified one file!
git commit -m "firtst commit"


Well, we will submit our changes locally. Note that this has not been submitted to our remote repository!
After commit, we can see our changes
cuitmnc@cuitmnc ~/testgit $ git commit -m "first commit"
[master (root-commit) a39fb74] first commit
2 files changed, 7 insertions(+)
create mode 100644 README.md
create mode 100644 code/testgit.c


Next, we need to connect our local repository with the remote repository in order to upload the code!
git remote add origin https://github.com/minchina/testgit.git


Map our repository to the remote!
input the command
git push -u origin master

According to the prompt, enter the user name and password we registered in github, you can push the local code to the remote!
We refresh our git page to see our code and upload successfully!

3.4 Update our code
I modified the testgit.c file in the code folder and added a line of code to it!
At the same time, we use
  
git add .

Add our code to the cache
  
git commit -m "update:code/testgit.c"

Submit the modified code, here is still not submitted to the remote end, only after using the git push command will the code be submitted to the remote end!
  
git push

     Commit our code to the remote refresh our git page
again !

We can see that we have two commits. The common commit is to record the status of our code. When we make an error in the process of writing code later,
we can go back to each `commit!
Four: Code description:
git workflow: In fact, the git local warehouse is jointly managed and implemented by three parts. The first is your working directory, which holds the actual files, the second is the staging area, which temporarily holds your changes,
and the last is the HEAD area, which points to the result of your last commit!
git init

Initialize git local folder!
git add filename
   
git add .

Propose changes, commit them to the cache, this is the first step in a git commit!
git commit -m "code commit information"


The actual submission of the code command, now the changes have been submitted to HEAD, but not yet to the remote repository!
git remote add origin <server>


Connect to remote repository
git push origin master


Commit changes to the remote, master is your branch name! You can replace master with whatever branch you want to commit to!
Five: Summary
Here I only briefly introduce the simplest usage of git! It also has many other functions! I will continue to explain git in the next article!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326535643&siteId=291194637