Transferred from: https://www.cnblogs.com/Juvy/p/3556902.html
Advantages of Git:
1 You can create a branch;
2 versioning is based on each submission and does not need to consider how many files are submitted at a time.
Download:
Download URL: http://git-scm.com/download, according to your operating system to select the appropriate installation treasure, after downloading directly follow the default installation (this article describes all Windows-based operating systems).
Overview:
The repository location for Git source manager can be based on local server and remote server two ways:
The local server is mainly used to manage its own code, the machine as the source control server;
The remote server is used to expose the source code and is used by multiple people to edit the code, primarily for team development.
Git source code submission process, you can use the following image to represent:
Your local repository consists of three "trees" maintained by git:
1) 工作目录(WorkDir)
, it holds the actual document;
2) 缓存区(Index)
, it's like a cache area, temporarily save your changes;
3) HEAD
, pointing to the result of your most recent commit.
After three steps above, your changes are now in the HEAD of the local repository, but the source code is not saved (pushed) to the remote repository, you can execute the following command to commit the changes to the remote repository: git push origin master,(master表示你要提交的分支,
You can put the master Switch to any branch you want to push)
How to use:
1 initialization, creation of the project;
1) using local or local area network computer as the source code Management Server,
A) You need to install Git on the source control server
b) Then create a directory (such as Git) as the source code store root directory, such as "C:\\git"
c) go to the Git directory and click on the "Git init here" button in the right mouse menu to complete the initialization (or use the "Git Bash command-line program to initialize the GIT init" command);
D) Then create the project directory under the root directory, or create some files, such as the Readme (directory must contain files to be submitted, otherwise the empty directory will be ignored at the time of submission);
e) for the project directory that you created, you need to click on the "Git Commit Tool" button in the context menu of the repository root and click the "Commit" button in the pop-up interface, or click "Git Bash" in the context menu of the repository root to pop up the command line window and enter: git Add. Enter git-commit-m ' Some message ' to enter to commit the initialization directory and file to the Code warehouse
2) If the Oschina server is a source control server, the initialization step is omitted, the account number must be registered in Oschina, and the project will be created online through the features provided by Oschina. Example of Access address:
A) HTTP mode: Http://git.oschina.net/UserName/Test.git
b) SSH mode: [Email protected]:username/test.git
2 Cloning a file from a git repository to a local
1) Local git repository: Enter the directory in which you want to download the code: c:\\git-workspace-local, click on the "Git Bash" button in the context menu, pop up the command Line window, enter the command:git clone ' local git repository root directory ', This article is "C:\\git"
2) Local area network or Oschina Warehouse: Enter the directory to download the code: C:\\git-workspace-oschina, click on the "Git Bash" button in the context menu, pop up the command Line window, enter the command:git clone ' remote git repository address ', such as: Http://git.oschina.net/UserName/Test.git or [email protected]:username/test.git (I use the GIT protocol to clone the time of the error, I do not know why, but also to read the person to sue, thank you!) )
3 creating branches, creating branch operations intelligence is created in source code manager, not local workspace
1) Use the local or LAN computer as the source control server: In the source Code Manager server warehouse root directory, click "Git History" in the context menu, then click the right mouse button to create the branch in the upper left corner of the "Gitk:git" form.
2) remote server (Oschina), created directly through the "Create branch" function of the website;
4 Branch switching: Git checkout Branchname
5 File Submissions
1) In the Explorer, create/Modify/delete/file, or execute the touch filename command in the GIT Bash tool to create the file
2) by executing: git add filename (with ".") The replacement file name represents all files submitted to the current directory, and the changes are submitted to workspace;
3) by executing: git commit-m ' Some message of this commit ', commits the modification to the buffer;
4) by executing: Git push origin branchname (local storage), or by executing git push enter user name Enter password return (remote server) Commit the modification to the source control repository
Note: At the time of submission to the local repository, the source control warehouse is best to switch to a different branch than the currently committed branch (for example, there are now two branches: Master and Mybranch, the current workspace mybranch checkout, in the execution of Git, when performing step fourth above) In the push, the source control repository is best to switch to the master branch, otherwise it will be wrong to execute the git push.
6 folder submission: Do not directly support the submission of empty folders, you need to create a file in the file, and then submit the file, so that the file is in the same folder submitted.
Common errors
1 when using git push code to the Data warehouse, the following error is indicated:
[Remote rejected] master, master (branch is currently checked out)
remote:error:refusing to update checked out Branch:refs/heads/master
Remote:error:By default, updating the current branch in a Non-bare repository
Remote:error:is denied, because it'll make the index and work tree inconsistent
Remote:error:with What do you pushed, and would require ' git reset--hard ' to match
Remote:error:the work tree to HEAD.
Remote:error:
Remote:error:You can set ' receive.denycurrentbranch ' configuration variable to
Remote:error: ' Ignore ' or ' warn ' in the remote repository to allow pushing into
Remote:error:its Current Branch; However, this isn't recommended unless you
Remote:error:arranged to update their work tree to match the what's pushed in some
Remote:error:other.
Remote:error:
Remote:error:To squelch This message and still keep the default behaviour, set
Remote:error: ' receive.denycurrentbranch ' configuration variable to ' refuse '.
to [email protected]:/var/git.server/.../web
! [Remote rejected] master, master (branch is currently checked out)
Error:failed to push some refs to ' [email protected]:/var/git.server/.../web '
Workaround:
This is because Git rejects the push-to-current branch operation by default and needs to be set up to modify the following code after the. git/config file is added:
[Receive]
Denycurrentbranch = Ignore
Unable to view the cause and resolution of files in a push git: git reset--hard in the repository root git Bash Command window to see what's behind the push.
Best to use when initializing remote warehouses (do not know why, use this command to create 31 empty warehouses after creating a warehouse, and you cannot see the project files)
Git--bare init
Instead of using:git init
The exact difference between git init and git--bare init: http://blog.haohtml.com/archives/12265
Two articles that suggest git to learn:
1) git-Easy guide
2) Graphic git[highly recommended]
[email protected] source control using journal "Go"