git installation, use tutorials, problems encountered, and basic common command collection

Source: Internet
Author: User
Tags switches using git git clone

In the last few days after installing Git but encountered many problems after a lot of search, found a few really practical ways to share here:

1.Git Use Tutorial

A little more, see this link: git using tutorials and basic common commands

2. The problems encountered

Original link: http://blog.csdn.net/dengjianqiang2011/article/details/9260435

If you enter $ git remote add Origingit@github.com:djqiang (GitHub account name)/gitdemo (project name). Git

Prompt error message: Fatal:remote origin already exists.

The solution is as follows:

1. First enter $ git remote RM origin

2, then enter $ git remote add Origin git@github.com:djqiang/gitdemo.git will not be an error.

3, if the input $ git Remote RM origin or error, error:could not remove config section ' Remote.origin '. We need to modify the contents of the Gitconfig file

4, find your GitHub installation path, mine is C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720b b5c8\ etc

5, find a file named Gitconfig, open it to the inside of [remote "origin"] that line deleted.

If you enter $ ssh-Tgit@github.com
Error message: Permission denied (PublicKey). Because the newly generated key cannot join SSH, it will cause the connection to be GitHub.

The solution is as follows:

1, enter $ ssh-agent First, then enter $ ssh-add ~/.ssh/id_key, so that's OK.

2, if still not, enter Ssh-add ~/.ssh/id_key command after the error could not open a connection to your agent. Solution is key with git GUI ssh tool Generated, so that when the key is directly saved in SSH, do not need to ssh-add the command to join, and other User,token configuration are done with the command line.

3, it is best to check if you copy the contents of the Id_rsa.pub file has no extra space or blank line, some editors will help you add these.

If you enter $ GIT push origin master

Prompt error message: error:failed to push som refs to ....

The solution is as follows:

1, first enter $ GIT pull origin master//First pull the remote server github the file above

2, then enter $ GIT push origin master

3, if there is an error fatal:couldn ' t find remote ref Master or fatal: ' Origin ' does not appear to be a git repository and fatal:could not Read from remote repository.

4, you need to re-enter $ git remote add origingit@github.com:djqiang/gitdemo.git

The process of creating a project locally using Git

$ makdir ~/hello-world//Create a project Hello-world
$ cd ~/hello-world//Open this project
$ git init//initialization
$ Touch README
$ git Add Readme//Update Readme file
$ git commit-m ' the ' a '//submit update and comment information "A-commit"
$ git remote add origingit@github.com:defnngj/hello-world.git//Connect to the GitHub project
$ GIT push-u origin master//update local project to GitHub project

Gitconfig configuration file

Git has a tool called Git config, which allows you to get and set configuration variables that control all aspects of Git's appearance and operations. These variables can be stored in three different locations:
1./etc/gitconfig file: Contains values that apply to all users of the system and to all libraries. If you pass the parameter option '--system ' to git config, it will explicitly read and write this file.
2.~/.gitconfig files: specific to your users. You can make git read or write this particular file by passing the--global option.
3. config file located in git directory (i.e.. git/config): Regardless of what library you are currently using, specific points to that single library. Each level overrides the previous level's value. Therefore, the value in. Git/config overrides the same value in the/etc/gitconfig.
In Windows systems, Git looks for a. gitconfig file in the $home directory (for most people, under C:\Documents and Settings\ $USER). It also looks for/etc/gitconfig, although it is relative to the Msys root directory. This could be anywhere you decide to install git when you run Setup in Windows.

Configure related information:

2.1 The first thing to do when you install Git is to set your user name and e-mail address. This is very important because this information is used every time that git commits. It is permanently embedded in your submission:

$ git config--global user.name "John Doe"

$ git config--global user.email johndoe@example.com

2.2 Your editor (Your Editor)

Now that your logo is set up, you can configure your default text editor, and Git will use the text editor when you need to enter some messages. By default, Git uses your system's default editor, which is usually either VI or VIM. If you want to use a different text editor, such as Emacs, you can do the following:

$ git config--global core.editor emacs

2.3 Check your Setup (Checking Your settings)

If you want to check your settings, you can use the GIT config--list command to list all the settings that git can find at this point:

$ git config--list

You can also look at the current value of a particular keyword that git thinks of, using the following command git config {key}:

$ git config user.name

2.4 Get help (Getting helps)

If you need help with Git, there are three ways to get the man page (manpage) Help for any git command:

$ git Help

$ git--help

$ mans git-

For example, you can run the following command to get Help on the hand album for config commands:

$ git help config

3.Git basic commonly used commands are as follows:

MKDIR:XX (Create an empty directory XX refers to the directory name)

PWD: Displays the path to the current directory.

Git init turns the current directory into a manageable git repository that generates hidden. git files.

git add xx adds the xx file to the registers.

Git commit–m "XX" Submit file –m is followed by comments.

Git Status View warehouse status

git diff xx View xx file modify those contents

git log View history

git reset--hard head^ or git reset--hard head~ rewind to previous version

(If you want to back up to 100 versions, use Git Reset–hard head~100)

Cat xx View xx file contents

Git reflog View history's version number ID

Git checkout-XX to remove all changes in the work area of XX files.

git rm xx Delete xx files

Git remote add Origin https://github.com/tugenhua0707/testgit associated with a remoting library

Git push–u (not needed for the first time with-U) Origin master pushes the current master branch to a remote library

git clone https://github.com/tugenhua0707/testgit from the remote library

git checkout–b dev creates dev branch and switches to Dev branch

Git branch view all current branches

Git checkout master switches back to master branch

git merge dev merges the Dev branch on the current branch

git branch–d dev Delete Dev branch

GIT branch name to create a branch

Git stash to hide the current work and continue working after resuming the scene

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.