Git tools are often used when using Github or Gitee (code cloud). But how should git tools be used? I’ll start from the beginning with the example of synchronizing to the code cloud.

First install git and configure it

1, download Git:download

2. Initial Git configuration:

After installing Git, you need to configure the user name and email address for submitting Git. User Name Fill in your user name or nickname on Gitee. Submit email and set it on Gitee.

Then you need to set it up in Git. Open the terminal (CMD) or right-click “git bash here” and enter the following two commands to complete the configuration:

Git config --global user.name "git config --global user.nameCopy the code

Such as:

git config --global user.name "user1"
git config --global user.email "[email protected]"
Copy the code

In this way, the nickname is set as user1, the submit mailbox is [email protected], and when you set yourself, change to your own nickname and mailbox.

The configuration file is in the.gitconfig file in our user folder and can be opened as a text document or edited.

2. Create an online warehouse and synchronize our local projects to the warehouse for the first time

1. Create a new warehouse on Gitee

Do not add the gitignore, readme. md, and LICENSE files to a new repository. Keep the repository empty for future synchronization. Otherwise, errors may occur.

2, create.gitignore in the local folder to be synchronized

Open and edit a text document.

.gitignore filters out files that we don’t want to sync. The syntax is as follows:

Classpath // The. Classpath file *.class is not uploaded during synchronization // Do not upload all class files ABC */ / Do not upload files whose names start with ABC (for example, abc_pidxxx) * ABC */ / Do not upload files whose names start with ABC during synchronization. Ign */ / Do not upload folders whose names start with ign*/ // do not upload the folder whose name contains ign. // do not upload the folder whose name contains ign. // do not upload the folder whose name contains ign.Copy the code

3. Create a local repository with our code projects

Open our local project folder and right-click “git bash here”. You can also open the terminal (CMD) and run the CD command to go to your project folder.

Enter the following command:

git init
Copy the code

You can see that we have generated a hidden.git folder in the project folder. This folder identifies the project as a local repository and stores the information about our repository.

Then add all files to the repository:

git add .
Copy the code

Notice add has a.

Then commit the file in our repository. This is very important because you cannot upload code without this step:

Git commit -m "initial commit"Copy the code

We then link the repository to our remote repository, that is, to the Gitee repository we created:

Git remote add Repository aliasCopy the code

Warehouse alias can be arbitrary, but the back to remember their own warehouse alias, because the back synchronization also need to use the warehouse alias, equivalent to this step to your warehouse named, you also want to remember the name. Such as:

git remote add fp https://gitee.com/user/exa.git
Copy the code

Rename the local warehouse later:

Git remote rename Original name New nameCopy the code

This named the repository FP and linked to our remote repository. The remote warehouse address can be found on the Gitee Warehouse page we created:

Empty warehouse copy address ↑ here

Normally in the clone/download button, select HTTPS, copy address ↑

Then submit the code:

Git push repository alias branch to commit toCopy the code

The alias has been set above. Branches can also be set when our Gitee repository is created. Usually we use a single branch, which means there is only one master branch in the warehouse.

When uploading synchronization, for example:

git push fp master
Copy the code

The master branch that uploads all of our code (projects) to the remote repository. Fp lets us alias the repository (for example) and wait for it to complete.

This successfully uploads the code to the remote repository. Go to the remote warehouse page can see our code up!

To create an open source LICENSE, you can do so at the prompt above the repository page.

Three, later synchronization of the warehouse

After engineering changes, resynchronization is easy:

Git add. git commit -m "Identify content" Git push repository alias branch to commitCopy the code

Git push… This step went wrong because it is possible to add files to the remote repository that are not locally available. So execute first:

Git pull Repository alias branchCopy the code

Synchronize the information from the remote repository

To perform:

Git push repository alias branch to commitCopy the code

That’s it!

Four, use Git to clone their own warehouse down and development synchronization

If we accidentally lose our local code or change the computer, after configuring the basic git information, we can clone our repository in the code cloud to continue development, then submit, and so on.

The address can be copied from the project repository home page:

Then open the command line or git bash in a folder and use the command:

Git Clone warehouse addressCopy the code

The online repository is then cloned to this folder.

Because cloning down from online warehouse warehouse, so the inside of the git repository information are, the remote address is also included in the warehouse, we can direct cloning down their own warehouse for development, and then according to the third part of the add, commit and push command can be synchronized, don’t need to like the next big step for the warehouse to initialize!

Go to our project folder, open the command line or git bash, and type:

git remote -v
Copy the code

You can see the warehouse information in:

Visible online clone down the warehouse, just continue to develop, submit, do not need to initialize, because it is already a Git warehouse and contains the remote address!

However, the cloned repository alias is Origin and can be modified using the git remote rename command.