GitHub getting started and daily operation commands (two errors and solutions are attached)

Source: Internet
Author: User

What's git & Git-Hub?

Development Environment: Linux and git tools


1. register an account first.

2. generate an SSH record (detailed on the official website, step-by-step)


3. Create a repository (used to store the project warehouse.

Create and write related names on GitHub, and then create a local "Contact" folder.

$ Cd ~ $ Mkdir github_JFF-RTOS // The local directory name and repository name are not necessarily the same, the relevant can be $ Cd ~ /Github_JFF-RTOS // enter the github_JFF-RTOS directory

Copy the code to be hosted here:

If you select Step 4, you must first execute

$git pull origin master

From github.com:mintist/JFF-RTOS * branch            master     -> FETCH_HEADMerge made by the 'recursive' strategy. .gitignore |   12 ++++++++++++ README.md  |    4 ++++ 2 files changed, 16 insertions(+) create mode 100644 .gitignore create mode 100644 README.md

Note: This is the two files automatically generated by GitHub.Pull (pull)Come down first ~~~

Otherwise ~~~ It's okay. Let's move on later ~~~

$ Git init // Initialization

Initialized empty Git repository in /home/mintist/github_JFF-RTOS/.git/
 

$ Git add. // Add all files to the index (if you do not want to add all files, you can use gitignore or add a specific file, as shown in the following figure) $ git commit-M "okay, this is not an RTOS ~~~ "// Submit it to the local repository, and then fill in the Update log

 4 files changed, 259 insertions(+) create mode 100644 Readme create mode 100644 app.c create mode 100644 core.c create mode 100644 core.h

$ Git remote add origin git@github.com: mintist/JFF-RTOS.git // Add to remote
$ Git push origin master // push to GitHub

If (you
Git pull origin masterAs I say, you will get)

Counting objects: 9, done.
Delta compression using up to 4 threads.Compressing objects: 100% (8/8), done.Writing objects: 100% (8/8), 2.96 KiB, done.Total 8 (delta 1), reused 0 (delta 0)To git@github.com:mintist/JFF-RTOS.git   c13a550..109de37  master -> master

Else

To git@github.com: mintist/JFF-RTOS.git
 ! [rejected]        master -> master (non-fast-forward)error: failed to push some refs to 'git@github.com:mintist/JFF-RTOS.git'To prevent you from losing history, non-fast-forward updates were rejectedMerge the remote changes (e.g. 'git pull') before pushing again.  See the'Note about fast-forwards' section of 'git push --help' for details.

If an error occursPullJust a moment ~~

For more information about common updates, see the following. It is available for test ~~~

To sum up the commonly used commands on GitHub in Ubuntu, skip the Settings section. Assume that the repository name is hello-world:

 

1. Create a New Repository:

Create and write related names and descriptions on GitHub.

$ Cd ~ /Hello-world // go to the hello-World Directory,The local directory name and repository name are not necessarily the same

$ Git init // Initialization

$ Git Add. // Add all files to the index (if you do not want to add all files, you can use gitignore or add a specific file. See the following figure)

$ Git commit // submit it to the local repository, and then fill in the Update log (-M "Update log" is also acceptable, such as $ git commit-M "My first vesion... ")

$ Git remote add origin git@github.com: wadeleng/hello-world.git // Add to remote

$ Git push origin master // push to GitHub

2. Update the project (new file added ):

$ Cd ~ /Hello-world

$ Git Add. // automatically determines which files are added, or manually add the file name.

$ Git commit // submit it to the local repository. If no parameter is added, a prompt will be displayed. Note: ^ = ctrl. Just follow the prompts to complete the operation ~~~

$ Git push origin master // not newly created, no need to add it to remote

3. Update the project (only files are deleted or modified without adding new files ):

$ Cd ~ /Hello-world

$ Git commit-A // record which files have been deleted or modified

$ Git push origin master // submit to GitHub

4. Ignore some files, such as *. O:

$ Cd ~ /Hello-world

$ Vim. gitignore // Add the file type to. gitignore and save

Then git add can automatically filter such files.

5. Clone the code locally:

$ Git clone git@github.com: wadeleng/ hello-world.git

If the Code already exists locally and there is an update in the repository, merge the changes to the local project:

$ Git fetch origin // obtain remote updates

$ Git merge origin/Master // merge the updated content to the local branch

6. Undo

$ Git Reset

7. Delete

$ Git RM * // RM is not used

// ------------------------------ Common Errors -----------------------------------

1. $ git remote add origin git@github.com: wadeleng/hello-world.git

 Error message: Fatal: remote origin already exists.

Solution: $ git remote RM Origin

Then the error will not be reported when you execute: $ git remote add origin git@github.com: wadeleng/hello-world.git

2. $ git push origin master

 Error message: Error: failed to push som refs

Solution: $ git pull origin master // first pull the file above the remote server GitHub and then push it.

//------------------------------------------------------------------------------

A Chinese git Manual: http://progit.org/book/zh/

Http://hi.baidu.com/wade_hit/item/848869db05e53af4cb0c391b

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.