Git gets started quickly

Time:2020-10-23

1、 Install Git

  • Download directly from official website
  • Git — version / / view version number

2、 Set Git

Generate key

  • Check to see if you already have the SSH key: Cd ~ /. SSH
  • If there is no key, there will be no such folder. If there is, it will be deleted by backup.
  • ssh-keygen -t rsa -C “[email protected]

Upload key

  • Take GitHub as an example, click setting > SSH and GPB keys > New SSH key, and copy and paste the secret key in the generated. Pub file
  • Then you can use SSH protocol to pull the push code

Set global base configuration

  • git config –global user.name “XXX” / / please change it to your own name
  • git config –global user.email ” [email protected] “/ / please change to your own email
  • git config –global push.default Simple / / git version 1.9.5 or above is required
  • git config –global core.autocrlf False / / let git ignore the conversion of windows / Unix line breaks
  • git config –global core.ignorecase False / / windows setting case sensitive

3、 Basic workflow

Attach git memo list first
Remember to pull first and then push. Conflicts are resolved locally
Finally, I like the collection of a dragon, hard core implantation, ha ha

Start a workspace

  • Init creates an empty git repository or reinitializes an existing repository
  • Clone uses SSH (recommended) or HTTP protocol to clone the repository to a new directory (recommended)
  • git config –global credential.helper Store / / remember git account password (avoid entering it every time you submit)

Work on current changes

  • Add adds the contents of the file to the index
  • MV moves or renames a file, directory, or symbolic link
  • Restore restore workspace files
  • RM removes files from the workspace and index

Check history and status

  • Bisection locates the bug submission through binary search
  • Diff shows the differences between commits, between commits and workspaces, and so on
  • Grep outputs lines that match patterns
  • Log displays the commit log
  • Show displays various types of objects
  • Status displays the status of the workspace

Expand, tag, and calibrate your history

  • Branch lists, creates, or deletes branches
  • Commit record changes to warehouse
  • Merge merges two or more development histories
  • Rebase re applies the commit on another branch
  • Reset resets the current head to the specified state
  • Switch switch branch
  • Tag create, list, delete, or verify a GPG signed tag object

coordination

  • Fetch downloads objects and references from another repository
  • Pull to get and integrate another warehouse or a local branch
  • Push updates remote references and related objects

4、 Git tools

Desktop tools

Git’s official graphical interface

  • Git GUI (advantage: browsing and selecting code changes before commit)
  1. Command line hit git GUI
  2. Windows Explorer, under the appropriate directory, right-click menu, GIT GUI here
  • Gitk (advantage: display version tree and historical information)
  1. Command line hit gitk — all&
  2. Git GUI > Menu > version Library > show history of all branches

Other alternatives

  • TortoiseGit (Windows)
  • Sourcetree (OS X and windows)

Git flow tool

install

OS X
brew install git-flow

Linux
apt-get install git-flow

Windows
wget -q -O - --no-check-certificate https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | bash

5、 Git flow workflow

appointment

Git gets started quickly

use

  • Initialization: git flow init
  • Start a new feature: git flow feature start myfeature
  • Publish a feature (i.e. push to remote): git flow feature publish myfeature
  • Get the feature of publish: git flow feature pull origin myfeature
  • Complete a feature: git flow feature finish myfeature
  • Start a release: git flow release start release [base]
  • Publish a release: git flow release publish release
  • Release: git flow release finish release
  • Don’t forget git push — Tags
  • Start a hotfix: git flow hotfix start version [basename]
  • Release a hotfix: git flow hotfix finish version

6、 Frequently asked questions

1. Git stash temporary modification

When we are developing a project, a change suddenly needs to be modified. In addition to committing the current project and then checking out to other branches, we can also stash the current changes and then switch to other branches without committing. In this way, we can reduce a commit (although git commit — amend can be used to modify the last commit)

Temporary modification

  • Git stash or git stash save “comments” to temporarily modify, which has been tracked by git, only code (not new) files have been modified
  • If there is a newly added file, you need to add the – a parameter (for example, GIT stash – A or git stash save – a “comment”), or git add first, and then use git stash or git stash save “comment” to temporarily modify

Take out the modification

  • Git stash pop takes the most recent temporary record and deletes the temporary record from the stash list
  • Git stash apply stash @ {ID} fetches a temporary record, but does not delete the record. The ID in stash @ {ID} starts from 0 by default, and the latest temporary record is 0

Temporary list

  • Git stash list view stash list
  • Git stash drop stash @ {ID} to delete a modification stage
  • Git stash clear clear clear clears all changes in the staging

2. View git logs

git log

  • Display all submitted version information
  • Add the parameter — pretty = oneline to filter and display the version number and the remarks when submitting

git reflog

  • View all operation records of all branches (including deleted commit records and reset operations)

Free shuttle git version

  • Git reset — hard head ~ 1 back to the previous version
  • Find the deleted commitid through git reflog
  • Git reset — hard commit to return to the specified version

3. Git cherry pick pick pick submit

Get a single commit from a branch and introduce it to your current branch as a new commit. When we need to merge the commit of other branches locally, we can use git cherry pick if we don’t want to merge the whole branch, but only want to merge a certain commit into the local current branch

  • 1. First, switch to the development branch and click the GIT log command to find the commit records to be merged, such as commitid: 7fcb3defff;
  • 2. Then, switch to the master branch and use the GIT cherry pick 7fcb3deff command to merge the commit record into the master branch, which is only locally merged into the master branch;
  • 3. At this point, the branch of the master commit is merged to the branch of the master.

Common options:

  • –Continue continues the current cherry pick sequence
  • –Quit exits the current Chery pick sequence
  • –Abort cancels the current cherry pick sequence and restores the current branch
  • -n. — no commit do not commit automatically
  • -e. — edit edit submit information

4. The difference between tag and branch

  • Tag corresponds to a certain commit. It is a point and cannot be moved.
  • A branch corresponds to a series of commit. It is a line formed by many points. It has a head pointer and can be moved by the head pointer.
  • Creating a tag is a commit based on a local branch, and it is different from pushing a branch. In other words, the branch has been pushed to the remote branch, but your tag does not. If you push a tag to a remote branch, you need to execute the push command of the tag separately.

5. How to switch the way to link git server: SSH or HTTP

Git remote set URL origin < URL to Modify >

Systematic learning

《 Pro Git 》
《 Git Magic 》
GitHub secret

Recommended Today

Blog based on beego, go blog

Go Blog A beego based development, can quickly create personal blog, CMS system Include functions see Official website of go bloggo-blog.cn Demo siteleechan.online Update log time function January 23, 2020 New top post function February 2, 2020 New custom navigation function February 4, 2020 New site announcement function February 6, 2020 New link module February […]