Github for Mac Frequently asked questions

Source: Internet
Author: User
Tags svn svn update hosting using git version control system git commands

Hosting your code on GitHub

GitHub is a code hosting platform for program apes and a Git-based, open source distributed version control system. However, when you land on GitHub, it doesn't have a good code-uploading system for you, because it's a git-based distributed version Management department. So how do you upload your local code to github faster and more efficiently? First, we need to install git locally so that we can use the git command line in our local environment (for example: $ git add index.html) The next step is to connect to your GitHub account so that you can upload your code files, and each change will form a version record, which is helpful for team collaboration.

Install Git

This is mainly about the Mac system, Windows is the same, but the MAC is under the terminal, and Windows is under the CMD. Install Git, the recommended installation of Apple's Xcode,xcode integration of Git, the latest version of Xcode has been installed by default git. After the installation is complete, you can use the GIT command-line tool.

Of course, first you need to register for a GitHub account.

Configure account information

Enter the following command line under CMD or terminal:

git config--global user.name trigkit4
git config--global user.email [email protected]

Of course, this is my account information, you need to replace them with your own.

Create a local SSH

This is a way to transfer code, fast and secure. SSH is currently a more reliable protocol that provides security for Telnet sessions and other network services.

Enter the following command line in terminal or cmd:

Ssh-keygen-t rsa-c "[Email protected]"

Of course, the mailbox is still replaced with the one you used to register for GitHub. As shown

Path selection: After using this command, you will be prompted to select the Ssh-key build path, where the direct click to enter the default, the generated Ssh-key in the default path;
Password Confirmation: Here we do not use a password to log in, with a password too troublesome;

Configure SSH to GitHub

Go to the folder under Mac OS X and/users/your computer user name/.ssh.

Windows should be (C:\Documents and settings\administrator\.ssh (or C:\Users\ own computer user name \.ssh).

Then open id_rsa.pub with Notepad and copy all the code inside to GitHub's ssh.

Id_rsa.pub File Contents:

Ssh-rsa aaaab3nzac1yc2eaaaadaqabaaabaqds0qltpontavr43aqntx4obosg2r3qlwubmyvfgjsidx6nwd5raidlblemwifldcpvpqkvk5s /bty4vtuwqey6fkq/tzbkksqn1wuydcsfjlf8bupmfdkboth9nakesknsiwdranevbmb5voahm8t+hfgdzg7tz4ygzcntwvdpbyrd/ 4jgeazws2d7cumeuyb+fxddtqy9ymjjm+82ypfr//blyzrjo3syadnpo3vdoazco1isky+p/0nnn/obc4t2y2+ ohbaqjv9h37f9s8ushgdmzovlicri4poni0i70xj+t/hnost8fmec+vm9usyn+ndawz2owjikkgln1job [email protected]

Login to GitHub website, click Settings--ssh keys--click on the Add SSH key on the right, then you know.

Verify that the configuration is successful:
Copy the following code:

ssh-t [email protected]

Then the following message appears:

Warning:permanently added the RSA host key for IP address ' 192.30.252.131 ' to the list of known hosts.

Hi hawx1993! You've successfully authenticated, but GitHub does not provide shell access.

Verification may let you enter Yes, when the above information, the configuration is successful, you can connect to GitHub;

To create a version library

The first step is to create a repository locally with the following code:

$ mkdir Test #test是你的文件夹的名字
$ CD Test #进入test所在目录
$ pwd #pwd命令用于显示当前目录
/users/trigkit4/test #这是在我的Mac上的目录

The second step is to turn this directory into a repository that git can manage by using the GIT init command:

$ git init

The following information is then output:

Initialized Empty Git repository in/users/trigkit4/banner/.git/

The. Git directory here is used by Git to track the management repository, which is hidden by default.

Third, next, create your own new repository on GitHub, and then next,

mkdir test
CD test
Git init
# Initialize your git repository
Touch README
# Create a file named README
git add README
# Add README to cache
Git commit-m ' first commit '
# Commit your files to local repository

We then transfer the local files to GitHub using the following command:

Git remote add Origin https://github.com/yourname/test.git
Git push-u Origin Master

Cloning from an existing warehouse

git clone git://github.com/yourname/test.git
git clone git://github.com/yourname/grit.git mypro# clone to a custom folder

Local

git add * #跟踪新文件

RM *&git RM * #移除文件
Git rm-f * #移除文件
git rm--cached * #取消跟踪
git mv file_from file_to# rename trace file

Git log# View commit record

Git commit# commit Updates
git commit-m ' message '
Git commit-a# skip using the staging area and save all tracked files for submission
Git commit--amend# modify the last Commit

git Reset HEAD * #取消已经暂存的文件

Git checkout--file# undo file Changes (remove files from staging area)
git checkout branch|tag|commit--file_name# remove file from repository overwrite current branch
Git checkout--. #从暂存区去除文件覆盖工作区

Branch

git branch# lists local branches
Git branch-r# lists the remote branch
Git branch-a# lists all branches
Git branch-v# View information about the last commit object for each branch
Git branch--merge# View the branches that have been merged into the current branch
Git branch--no-merge# View as a branch merged into the current branch

Git branch test# new test Branch
git checkout test# switch to test branch
Git checkout-b test# new + Switch to test branch
Git checkout-b test dev# builds a new test branch based on Dev and switches

git branch-d test# Delete Test Branch
git branch-d test# Force Delete test Branch

Git merge test# merge the test branch into the current branch
Git rebase master# commits the master to the current branch

Common errors

The first one:

ERROR:SRC Refspec Master does not match any.
Error:failed to push some refs to ' https://github.com/yourname/test.git '

Enter the following code:

$ CD MyProject
$ git init
$ git Add.
$ git commit-m ' initial commit '
$ GIT push origin master

The second one:

Git push-u origin master fatal:unable to access ' https://github.com/ZeyuChen/TPlus.git/': Sslread () return error-9806

The error is that HTTPS hangs, the solution is in the project directory inside the. git/config file, modify the repo URL connection, from HTTPS to the GIT protocol can be modified.

Originally URL = Https://github.com/ZeyuChen/TPlus.git

Revision changed to

[remote "origin"]
url = ssh://[email Protected]/zeyuchen/tplus.git
Fetch = +refs/heads/*:refs/remotes/origin/*

Push Again is OK.

Git commands in a detailed

Now that we have the local and remote repositories, let's try using Git's basic commands:

Git Pull: Updates the code locally from other repositories (both remote and local), for example: ' Git pull Origin master ' is updating the code for the Origin repository to the local master primary branches, This feature is similar to the SVN update

Git add: is to add the current changes or new files to the Git index, added to the Git index is recorded in the version history, this is a step before committing, such as ' git add app/model/user.rb ' will increase app/model/ USER.RB file into the git index, which is similar to the SVN add

git rm: Removes files from the current workspace and index, such as ' git rm app/model/user.rb ', which is similar to SVN's RM, Del

Git commit: Commit changes to the current workspace, similar to the SVN commit command, such as ' Git commit-m story #3, add user Model ', which must be submitted with-m to enter a commit message, This feature is similar to the SVN commit

Git push: Updates the local commit code to the remote repository, such as ' Git Push origin ', which updates the local code to the remote repository named Orgin

git log: View the history log, which is similar to the SVN log

git revert: Restore a version of the changes, you must provide a specific git version number, such as ' git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ', git version number is a generated hash value

git mind Map

Github for Mac Frequently asked questions

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.