GitHub installation and use in Ubuntu environment

Source: Internet
Author: User

Install Git
sudo apt-get update  sudo apt-get install git
    • 1
    • 2
    • 1
    • 2
Configure your GitHub
git config --global user.name "Your Name"      git config --global user.email "[email protected]"
    • 1
    • 2
    • 1
    • 2
View configuration information
git config --list
    • 1
    • 1
Edit configuration information
gedit ~/.gitconfig
    • 1
    • 1
Modify
[user]             name = Your Name             email = [email protected]  
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3
Create a public key
ssh-keygen -C ‘you email [email protected]‘ -t rsa
    • 1
    • 1

This establishes the corresponding key file under the user directory ~/.ssh/

Upload Public key

Select Account Settings in the upper-right corner of the github.com interface and select SSH public Keys to select New Add.

Title can be arbitrarily named, the content of Key is copied from the content of ~/.ssh/id_rsa.pub, after completion, you can re-use

ssh -v git@github.com
    • 1
    • 1

To test. See the following information to indicate that the validation was successful.

.........各种信息.........
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
How to use GitHub

Login to the GitHub account, click New Repository, fill in the warehouse name;
There are two ways to initialize a warehouse: Initializing a new warehouse in a local working directory, cloning from an existing warehouse
(1) Initializing the new warehouse in the local working directory
Enter the project directory:

touch README.mdgit init     ##重新初始化Git仓库地址。如:现存的 Git 仓库于 /home/zzh/code/.git/git add *    ##添加上传的文件git commit -m ‘initial project version‘git remote add origin [email protected]:TimorChow/FirstDemo.git ## 即刚刚创建的仓库的地址git push -u origin master ##推送代码到远程代码库
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

(2) Cloning from an existing warehouse

    add origin git_address          #git_address即现有仓库的地址       #如 [email protected]:TimorChow/baike_spider    git push -u origin master
    • 1
    • 2
    • 3
    • 4
    • 1
    • 2
    • 3
    • 4

To copy a project from GitHub to a local:

Git Clone git_address

(3) Local Code update push

    #更新文件 VI README#自动commit更改文件 git Commit-A#更新至远程 git push Origin master #创建和合并分支 git branch  #显示当前分支是master git branch new-feature  #创建分支 git checkout new-feature Span class= "hljs-comment" > #切换到新分支 vi page_cache.inc.php git add page_cache.inc.php  #Commit to local git git Commit-a-m  added Initial version of page cache " #合并到远程服务器 Git push origin new-fea Ture  #如果new-feature Branch Mature, feel the need to merge into master git checkout master git merge new-feature git branch git push # The New-feature code is also merged in master             
      1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • Ten
    • one
    • 2
    • (
    • )
    • +
    • +
    • /
    • 0
    • +
    • all
    • +
    • +
    • +
    • -
    • 29
    • +
    • +
    • all
    • +
    • +
    • PNS
    • up
    • i>39
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21st
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

The GitHub repository you just created has an error in the push code:

$ Git push-u Origin Master
to [email protected]:* */demo.git
! [Rejected] master, master (Non-fast-forward)
Error:failed to push some refs to ' [email protected]:* */demo.git '
Hint:updates were rejected because the tip of your current branch is behind
Hint:its remote counterpart. Merge the remote changes (e.g. ' git pull ')
Hint:before pushing again.
Hint:see the ' Note about Fast-forwards ' "Git push–help ' for details.

Online search, because the remote repository and my local repository conflict caused, and I created the Repository, on the GitHub repository page click on the Create Readme.md file button to create a description of the document, but did not pull to local. This creates a problem with version conflicts.

There are several workarounds:

1. Use the force Push method:

$ Git push-u origin master-f

This will make remote modification lost, is generally undesirable, especially when multi-person collaborative development.

Remote repository modification pull down before 2.push

$ Git pull Origin Master

$ Git push-u Origin Master

3. If you do not want to merge remote and local modifications, you can create a new branch first:

$ git branch [name]

Then push

$ Git push-u origin [name]

GitHub common operations and common errors: http://blog.csdn.net/god_wot/article/details/10522405
Reference article: http://blog.csdn.net/small_rice_/article/details/45095323

GitHub installation and use in Ubuntu environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.