preface

There are two ways to obtain a Git repository: first, import all files from the existing project directory to Git, and second, clone the project from Git repository to Git

Here without Git installed ha, friend in need can view the blog: www.cnblogs.com/poloyy/p/12…

 

Initialize the repository in an existing directory

For Windows, go to the local project directory, right-click to see git-bash, open the git operation screen, and enter the command

git init
Copy the code

Then you’ll see a.git folder in your directory

If not, check the hidden items as follows:

At this point, project initialization is complete; However, initialization is not enough. You need to execute the following command again

1 git add .
2 git commit -m "init project"
Copy the code

Git add. : Adds all files in the current directory to the staging area

Git commit: Commit the staging file to the local repository

To push a local repository to a remote repository, you first have to add the local repository to the remote repository by executing the following command

git remote add origin [url]
Copy the code

Origin: can be understood as the alias of the warehouse, you can choose Github, Gitee, as you like; But Origin is the default remote repository name

Url: fill in your remote warehouse address, [email protected]: zTree/zTree. Git, gitee.com/zTree/zTree…

Finally, push local files

git push
Copy the code

 

Anomaly 1

Cause: The current branch is not associated with the remote branch, so the commit code failed

Solutions:

  1. Git push Origin master directly to the specified master branch
  2. Do git push –set-upstream origin master as described above
  3. Git push -u origin master

If method 2 and 3 are not adopted, each push should be pushed by the command of method 1. Git push: Git push: git push: git push

 

Abnormal Case TWO

If Permission denied (publickey) is displayed after push, your local publickey has not been added to the remote repository

 

Abnormal Case 3

If fail is displayed, you can force push

git push -f
Copy the code

 

Lazy tutorial, quick fix

To initialize a warehouse in a local project, you can use the following command to type it line by line

3 git add readme. md 4 git commit -m "first commit" 5 git remote add origin [email protected]: git 6 git push -u origin masterCopy the code

 

Clone existing warehouse

Git clone is an example of how you can use git clone to pull out all versions of files in your repository.

1 # for the HTTPS url format 2 git clone https://gitee.com/zTree/zTree_v3.git # 3, 4, 5 git clone url for SSH format [email protected]:zTree/zTree_v3.gitCopy the code

This will create a folder named zTree_v3 in the directory where you executed the command. If you want to customize the name of your local repository, use the following command

git clone [email protected]:zTree/zTree_v3.git myTree
Copy the code

In this case, the name of the repository created locally becomes myTree