Mac Install Git

Source: Internet
Author: User
Tags install homebrew key string ssh git clone

git installation

There are two ways to download git

      • Download the installation package directly, Git
      • Download with homebrew command, but first you need to install homebrew
        • After the terminal executes the command installation,homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
        • When you are done, install git with a later command,brew install git
        • installation directory /usr/local/share/emacs/site-lisp/git

After you install git, configure your user name and user mailbox to use this information every time you interact with git.

git config --global user.name "your_name"  git config --global user.email "[email protected]"

Configuration information can be changed, and later you want to change it using the instructions above. You can also use git config --list the instructions to view git configuration information.

Git by default is case insensitive, that is, a file name is a letter of the case of the conversion of the change of a word, Git ignores this change, resulting in the synchronization of code errors, so the recommended size of Git is set to be case sensitive.

false
Generate key

GIT associates a remote repository with a public key, saves the private key locally, and each time it interacts with the remote repository, the remote repository verifies the identity of the user with the public key. Use the following instructions to generate the key.

ssh-keygen -t rsa -C "[email protected]"

After generating the key, the local /Users/当前电脑用户/.ssh directory will generate two files, the id_rsa id_rsa.pub id_rsa file is saved by the private key, saved locally, the id_rsa.pub file is saved by the public key, you need to upload the contents to the remote repository.

Gets the public key string specific operations such as.


Figure-1 Getting the public key
    • Enter cd the command to enter the current user directory
    • Enter ls -a instructions to view all files in the current user directory, including hidden files
    • Enter cd .ssh the command, enter the .ssh directory
    • Enter the ls instructions to view .ssh the files in the directory
    • Enter cat id_rsa.pub instructions to view id_rsa.pub the contents of the file
Remote repository Add encryption key

Using GitHub as an example, the public key is added to the remote repository, and the public key is already available, simply adding the public key to the remote repository.

Figure-1 adding a public key

In the Personal Settings page, left selected SSH and GPG keys , add public key on the right, title is the name of key, can be arbitrarily taken, can be changed, key is the public key we acquired above, completed after the Click add SSH key button, so the remote added to the key.

Locally associated Remote Repository
    • Execute the instructions under the Local folder and git init initialize the folder as a local repository.
    • Performgit remote add origin 仓库的ssh链接
    • Execute git pull instructions to pull the remote code to the local

After execution, the remote repository code has been synchronized to local.

Common git directives
  • Initialize configuration

    git config --global user.name “XXX"git config --global user.email “XXXX"
  • Set case sensitivity

    false
  • Generate key

    ssh-keygen -t rsa -C “your_email”
  • Clone the remote code to a local directory

    <远端git> <本地目录>
  • Submit Changes

    add <文件> // 将有修改的文件添加到本地缓存中 git add . 是添加所有修改git commit -m "本次修改信息" // 提交本次修改,一般是在git add之后操作git reset . // 撤销addgit rm --cached . // 撤销add
  • Switch branches

    <branch_name>
  • Create a new branch based on the current branch and switch to a new branch

    <branch_name>
  • The current branch merges other branches

    <branch_name>
  • The new branch in the far end is actually pushing the local branch to the remote

    git push origin <local_branch_name>:<remote_branch_name>
  • Deleting the remote branch is actually pushing an empty branch to the far end to cover the original remote branch.

    :<remote_branch_name>
  • Pull branches from the remote and establish corresponding relationships

    <local_branch_name> origin/<remote_branch_name>// 或者git branch —track <local_branch_name> origin/<remote_branch_name>
  • Local existing branches and remote branches to establish the corresponding relationship

    <local_branch_name> origin/<remote_branch_name>
  • Add Remote Library

    <远端库代称> <远端库地址>git clone <远端库地址> <目录> //不需要git init
  • Roll back to a commit version

    git reset --hard/soft <commit_id> // 回滚到某一个版本git reset --hard/soft HEAD~<num> // 回滚num个提交git revert <merge_commit_id> -m number // 撤销某一次merge
  • Force remote Overwrite Local

    git fetch --allgit reset --hard origin/<remote_branch_name>
  • Submit the Log View method

    log -p 每一次提交具体差异git log —stat 显示文件修改差异,没显示具体修改git log —graph 树形状提交记录,可查看分支合并信息
  • git pull —rebaseAfter conflict, resolve conflicts, use git add . and then usegit rebase --continue

  • Switch to a branch and apply a commit of another branch to that branch

    <branch_name>git cherry-pick <commit id>
  • The former represents the commit Cherry-pick to the current branch (left open right closed, not including Start-commit-id), which represents the commit Cherry-pick to the current branch (closed interval, including Start-commit-id).

    git cherry-pick <start-commit-id>..<end-commit-id>git cherry-pick <start-commit-id>^..<end-commit-id>
  • Tag

    • New tag

      git tag <tag_name > //lightweight label git tag -a <tag_name> -m  "tag_msg" //Note tag git tag -a < tag_name> <commint_id> //add tags to a commit        
    • Delete tag

      tag -d <tag_name>
    • View Tag

      tag // 查看所有taggit show <tag_name> // 查看某条tag
    • Commits to the remote

      git push Origin <tag_name> //commits a tag to the remote git push origin–tags //commits all tags to the remote  
  • Branch related directives

    -d <branch_name> // 删除某个分支git branch -D <branch_name> // 强制删除某个分支git branch -avv // 查看本地分支与远端分支关系,并且显示分支最新一次提交信息git remote show origin // 查看远端分支间关系

Mac Install Git

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.