How to configure and use GitHub in Ubuntu
1. Configure the github Environment
1. Environment: Ubuntu14.04
2. Apply for a github account
3. install and configure the git Server:
(1) install ssh: sudo apt-get install openssh-server openssh-client
(2) Start the ssh service: sudo/etc/init. d/ssh restart
(3) install the git server: sudo apt-get install git-core
4. Configure the ssh Public Key
(1) generate an ssh Public Key: ssh-keygen-C 'your mailbox address'-t rsa
Note: This command will be in the current user directory ~ /. Ssh/to generate a key file
(2) test smoothness: ssh-v git@github.com
(3) Upload the public key to github: Click profile in the account, select SSH and GPG keys, and click New SSH key ~ Copy all the content in/. ssh/id_rsa.pub to the Key edit box and Click Upload. For example
(4) reply to the email: After the public key is uploaded, github will send a confirmation email to your mailbox. You need to click "OK.
2. Use github to manage projects
1. Create a new repository in your github
2. initialize the Repository: Enter the project directory for version control.
Enter the command: git init
Note: after running, A. git hidden folder is added to the directory.
3. Configure git:
(1) enter the command: git config -- global user. name "your username"
(2) enter the command: git config -- global user. email your email address.
4. Add managed files:
Enter the command: git add ./
Note: This is to add all files under the directory. If you only add a file, the file name will be listed. if you add a directory, you can use * instead.
5. commit project:
Enter the command: git commit-m "Description"
Note: The-m parameter is followed by the description information submitted this time. It can be code modified and new functions.
6. Upload a project:
(1) enter the command: git remote add origin repository address
(2) enter the command: git push-u origin master
(3) enter the command: git pull
(4) enter the command: git push
Note:
(1) The "repository address" can be viewed in the github project repository,
(2) "git remote add origin repository address"
Pull, git push.
Iii. Common git commands:
1. git clone repository address // clone repository code to local
2. git diff // check the differences between local code and remote code
3. git pull // obtain the latest code remotely (when submitting code, do not submit it directly. Before submitting code, make sure that the local code is up-to-date, that is, execute git pull first)
4. git branch // view which branch of the local code belongs to the repository
5. git branch-a // view the branches of the Repository
6. git checkout branch name // switch Branch (Note: it is not recommended that you create a folder for a branch)
7. git clone-B branch name repository address // clone the repository code of the specified branch to the local
8. git push-u origin branch name (the branch name is usually master)
Iv. git FAQs:
Git pull failure problem: Sometimes git pull will fail, that is, local code conflicts with remote code, which needs to be solved manually.
Conflict Resolution:
1. git stash // return the local file to the previous operation
2. git pull // download the new Code
3. git stash pop // merges conflicting files. The "<>" symbol appears in the code, the code between symbols is part of the conflict between the local and remote code.
4. After the solution is completed, git pull, git commit, and git push