GitHub in Ubuntu

Source: Internet
Author: User
Tags commit ssh git client git clone git commands

Installation configuration and Code synchronization FAQ Git Common Command Reference

1. Installation configuration and Code synchronization

Step1: Installing the GIT client

sudo apt-get update  
sudo apt-get install git  

Step2: Configuring GitHub

git config--global user.name "Your name"  
git config--global user.email "youremail@domain.com"  

Step3: Creating a Public key

Ssh-keygen-c ' You email address@gmail.com '-t RSA   

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

STEP4: Uploading the 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

After the build succeeds with Notepad open id_rsa.pub, get SSH key public key, please note here must ensure no format paste, otherwise GitHub will error.

step5: Test it, please .

Ssh-v git@github.com   

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

STEP6: Open terminal in local project directory

step7: Initializing directory

Git init  

STEP8: Add files to git

git Add.  

Pay attention to the back. Represents the current directory. No prompt message is a good hint, but it doesn't say git will not return a hint.

Step 9: Submit all Documents

Git commit-m "Initial commit"-A  

M represents a message,-a represents all

If you are submitting a specific file instead of the entire project file, you can use:

Git commit-m "Initial commit" file  

File is specified

Step 10: Create a repository on GitHub
and copy the URL

Step 11: Commit to a git project

Git remote add Origin Ssh://yoursshurl

Yoursshurl for your newly created repository URL

STEP12: Submit Your code

Git push Origin Master  
3. Frequently Asked Questions

1, RT! [Rejected] Master--master (fetch first)

This error was found when the remote server was being push because the remote master was not synchronized
So we need to sync up first.
Git pull Origin Master
In the process of executing this code, Ubutun may jump into a Vim/nano edit file, this file without editing, you directly according to the file below the prompt column Ctrl + C exit the editor can be

Of course, you can also choose to upload the code in other branches (see section 4th for switching branches)

2. Changes not staged for commit during Git commit
Git add is required before commit and then push
The entire process:

Where Menudd is a directory or the file will be automatically updated with modified files

And then

$ git commit-m "asdf"

"ASDF" is an update comment
At last

Complete

3. Fatal:remote origin already exists.
In the execution

  $  git remote add Origin  Https://url

Error message:

Fatal:remote origin already exists.

Workaround:

$ git Remote RM origin

Then in the execution:

You won't report a mistake.

4. Error:failed to push som refs to ....

$ GIT push origin master

Error hint: error:failed to push som refs to ....
Workaround: First pull the file on github above the remote server first, then push up

5. Resolve conflicts and create branches
View all Branches

Git branch-a  

Create a new branch develop

git checkout-b Develop  

Switch to Master Branch

git checkout Master  

Switch to Bra Branch

git checkout Bra  

View your Branch

Git branch  

Merging branches

git merge Develop--NO-FF  
4. Common Git Commands

1. Create a new repository:
Create and write the relevant name and description on GitHub first.

$CD ~/coredump        
$git init                     //Initialize
$git Add.                   Add all the files to the index (do not want to add all the files, you can use Gitignore or add specific files)
$git commit               //submit to the local repository, and then fill in the Update log (-M "Update log" can also)
$git Remote Add Origin Https://URL       //Add to remote
$git push Origin master    //push to GitHub

2. Update the project (new file added):

$CD ~/coredump
$git Add.                  This will automatically determine which files are added, or manually add the file name
$git commit              //submit to the local repository
$git push Origin master    //not newly created, no add to the remote.

3. Update the project (no new files, only delete or modify the file):

$CD ~/coredump
$git commit-a          //record which files were deleted or modified
$git push Origin master  //Submit to GitHub

4. Ignore some files, such as *.O, and then you can git Add. can automatically filter this file

$CD ~/coredump
$vim. Gitignore     //Add the file type to the. Gitignore, save

5.clone code to Local:

$git Clone Https://URL

If the code exists locally, and the repository has updates, merge the changes into the local project:

$git Fetch Origin    //Get remote update
$git merge Origin/master//merge updated content into local branch

6. Revocation

$git Reset

7. Delete

$git RM  
5. Reference

Http://www.cnblogs.com/specter45/p/github.html
http://blog.csdn.net/small_rice_/article/details/45095323

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.