Git Learning Notes

Source: Internet
Author: User
Tags using git git commands

It used to upload code directly with GitHub for Windows graphics clients, didn't know git commands, and was far from playing the power of Git. Now in a CMS project, and finally need to deploy to the remote server, and after the front-end engineering thought of baptism, I can not bear the manual file to the server "FTP deployment Method", because this primitive inefficient error-prone, and seriously detrimental to maintenance updates. In the spirit of automation, I began to look at ways to deploy Web sites with git. Learning materials Link: http://blog.jobbole.com/78960/git warehouse (repo) refers to the directory where the project files are stored, and there is a. git hidden file in this directory (if not, generated with GIT init), which is the relevant file for version management. Git is the repository, the most important of which is the stage (staging area), the branch master that git automatically creates, and a pointer to master head. Files entering staging area are temporarily "locked" pending submission, the changes that occur after the file is added to staging area do not affect staging area, and are submitted in the staging area version. Note: You can use the wildcard character * in the command. Common CommandsGit init initializes the repository (--bare generates a bare library, which is the only file that records the repository's historical information, without a copy of the actual project source file) git add [file]: Add files to staging area to wait for commit. Changes that occur after the file is added staging area will not be committed unless it is added again. git commit-m [message]: Commits the file on the staging area to the current branch that the head points to git diff [file]: View the changes in the file relative to the branch git status [file]: View files status git checkout--[File ]: Overwriting the workspace file with the staging area file is equivalent to discarding the changes since the last Add. Git checkout. Indicates that the workspace file is overwritten with all files in staging area. git log view commit log git reflog view latest action log git reset--hard [version number] Restore the specified version of Git reset-hard head^ revert to the previous version (a ^ represents a version, or a ~[number] indicates the number of fallback versions) Branching PolicyThe General Master Branch is the most robust, used to release new versions, do not work on them, work on other branches, and then merge into Master. GIT branch [branch] creates a new branch git checkout [branch] switches to the specified branch (with the-B parameter indicating that a new branch is created at the same time). After switching the branch, the contents of the file in the repository will change to the same as the current branch. git merge [branch] merges the specified branch into the current branch. When a merge branch is in conflict with the current branch, GIT will label it in the merged file and must manually eliminate the conflict before committing it again. git branch-d [branch] deletes the specified branch git stash hide the current branch of the work site, such as the work is half-way unable to commit, but must switch branches, this command can be used at this time. Git stash list list is hidden work site git stash apply/drop recovery site/... and remove the hidden work site Remote OperationGit remote Library information (parameter-v view details) git remote add [remote branch] [Server]: Clone the local warehouse on the remote server, the remote library name defaults to origingit push [remote Branch ] [branch]: Push the branch to the remote repository (with the-u parameter after push on the first push) Git clone [remote address]: Clone the Remote (Github) repository locally, git automatically corresponds to the local master and Remote Master policy: which branches need to be pushed?
    1. Master is the main branch and needs to be synchronized with the remote at all times
    2. The development branch does not need to be pushed to the remote, can be merged into master and then pushed
Git pull branch from remote to local git branch--set-upstream-to [local branch] origin/[branch] associate local branch with remote branch

Multi-person Collaboration mode is generally the case:

    1. First, you can try to push your own changes with GIT push Origin branch-name.
    2. If the push fails, because the remote branch is older than your local update, you need to first try to merge with Git pull.
    3. If there is a conflict in the merge, the conflict needs to be resolved and committed locally. Then push origin branch-name with Git push.

Attached: How to deploy node. JS Project code to the server using git:

  1. Create the project directory on the server and initialize it to git repository: Git init, configured to allow receive code submission: git config receive.denycurrentbranch ignore
  2. Create a remote branch on a local project: Git remote Add branch name ssh://user name @ Remote address/project path/.git
  3. Push the project's master branch to the server: Git push remote branch name Master
  4. To the server-side git staus, you will find a heap of anti-operations in the staging area (such as delete files that should have been saved). At this point, the first update check out the code git update-server-info, git checkout-f, the effect is to restore all the files to the last commit version, the changes in the staging area are discarded.
  5. Then NPM install to fill up the node_modules on it!
  6. Server side Add Automatic Update hook script: 1) CD. git/hooks;2) Create a new post-receive or rename the post-receive.sample to post-receive, or use post-update to However, you need to delete the exec git update-server-info line in post-update, 3) Vim post-receive, copy the following to the file
    • #!/bin/sh
    • Unset Git_dir
    • Cd..
    • Git checkout-f
  7. Install PM2 to protect your website
  8. Under the Linux system to listen to less than 1024 of the port, the need for root authority, for this use a workaround, that is, the use of IP table set 80 port information and 3000 port to each other forwarding, this forwarding at the network card level, performance is high. Here's how:
    1. Input sudo iptables-t nat-a prerouting-p tcp--dport 80-j REDIRECT--to-ports 3000
    2. Switch to root user
    3. Input Iptables-save>/etc/iptables-rules
    4. Edit the/etc/network/interfaces file in the last line insert: pre-up iptables-restore</etc/iptables-rules for power-on auto-configuration

Git Learning Notes

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.