Upload and pull local files and remote Git warehouses through terminal commands!

upload

To upload a local file to a Git repository, the following steps need to be followed:

1. ** Initialize the repository (if not already initialized):**
 Navigate to the folder containing your project files, open a command line (windows) or terminal (git)

git terminal download: Git download and installation tutorial

and run the following command to initialize a new Git repository:

   ```bash
   git init
   ```

2. ** Add files to the temporary storage area :**
   Use the following command to add the files you want to upload to the temporary storage area of ​​the Git repository. Replace `<filename>` with the actual filename.

   ```bash
   git add <filename>
   ```

   You can also use the wildcard `*` to add all files:

   ```bash
   git add *
   ```

3. ** Submit changes :**
   Submit the changes in the temporary storage area to the local warehouse, and attach a commit message describing your changes. Replace `<message>` with a meaningful commit comment message.

   ```bash
   git commit -m "<message>"
   ```

4. ** The file has been uploaded to the local repository: **
   Now, your file has been successfully uploaded to the local Git repository.

Please note that the above steps only upload files to the local Git repository, and do not involve interaction with remote repositories. If you want to upload files to a remote repository (such as GitHub, GitLab, etc.), you need to connect your local repository to the remote repository and push the changes. This will involve using the `git remote` and `git push` commands.

If you want to upload files to an existing remote repository, you can perform the following steps:

1. ** Associate remote warehouse: **
   Suppose you have created a new warehouse on a remote warehouse (such as GitHub, GitLab, etc.). In your local repository, use the following command to associate the local repository with the remote repository. Replace <remote-name>with the name of your desired remote repository, usually "origin".

   ```bash
   git remote add <remote-name> <remote-url>
   ```

where <remote-url>is the URL of the remote repository. For example, the URL for a GitHub repository would be something like https://github.com/username/repository.git.

2. ** Push changes to the remote warehouse: **
   Use the following command to push your changes to the remote warehouse. Replace `<branch-name>` with the name of the branch you want to push, usually "main" or "master". <remote-name> is the name of the remote warehouse you previously associated

   ```bash
   git push <remote-name> <branch-name>
   ```

Pull (synchronously downloaded to the local warehouse)

If someone else made changes in the remote repository, you need to pull (fetch) those changes from the remote repository to your local repository. Use the following command:

   ```bash
   git pull <remote-name> <branch-name>
   ```

For example, to pull changes from the "main" or "master" branch of a remote repository:

   ```bash
  git pull origin main/master
   ```

Remember, Git is a powerful version control tool that helps you manage the history of your code and collaborate with your team. When using Git, make sure to read the documentation carefully and follow best practices.

Guess you like

Origin blog.csdn.net/qq_58647634/article/details/132400932