banner
wujiangbian

wujiangbian

How to use git to pull a project and deploy it to your own repository (self-storage)

Pull Project Code to Local#

1. Environment Dependency Preparation#

First, check what environment and dependencies this project requires before proceeding with the next steps.

2. Start Building#

Step 1: Clone the Code#

git clone URL
cd folder_you_cloned_to

Step 2: Build (Package)#

npm run build

Step 3: Results and Debugging#

Build result: After completion, web files will be generated in the dist folder.
Local development preview:

npm run serve

At this point, it is running in development mode, where the code is not compressed and contains debugging information. Once confirmed, you can proceed to the next steps to deploy the project to your own repository. Here, we take GitHub as an example:

Deploy the Project to Your Own Repository#

Step 1: Prepare GitHub Repository#

  1. Log in to your GitHub.
  2. Create a new repository. (Do not check to add a README file, add .gitignore, or add a license, as you have pulled someone else's project with existing files).
  3. Remember your repository name.

Step 2: Connect and Push from Local Terminal#

Now, return to your VS Code or command line window (make sure the path is at the root directory of your project folder).

Situation A#

If you have never run git commands in this project before (or if you are unsure, just execute the following commands in order):

Copy the commands below and execute them line by line:

# 1. Initialize git repository (it's okay if it shows Reinitialized...)
git init

# 2. Add all files to the staging area
git add .

# 3. Commit files to the local repository
git commit -m "first commit"

# 4. Rename the branch to main (GitHub now defaults to main, not master)
git branch -M main

# 5. Link to the remote repository
# ⚠️ Replace the URL below with the HTTPS address you saw after creating it on GitHub
git remote add origin https://github.com/your_username/your_repository_name.git

# 6. Push to GitHub
git push -u origin main

Situation B#

If step 5 reports an error "fatal: remote origin already exists," it indicates that you may have previously attempted to link (perhaps with the wrong address).

Solution:

# First, remove the old link
git remote remove origin

# Then re-execute the link command
git remote add origin https://github.com/your_username/your_repository_name.git

# Finally, push
git push -u origin main

Step 3: How to Modify Code and Push to GitHub#

The logic of Git is: any operations you perform locally (deleting, modifying, adding) need to be "told" to Git, and then "pushed" up. In other words, if you want to modify your project, you must go through three steps:

1. "Package" the modifications#

git add .

2. Label the package (this step is crucial, sometimes it may load very slowly)#

git commit -m "modify configuration file and delete unnecessary files"

(After executing this, you should see a list of the files you modified or deleted in the terminal)

3. Send the package#

git push

If you encounter an error after executing, you can first type git status. If you see a bunch of red file names, it indicates that you may have forgotten to add or commit.
But you may also encounter the following error:

$ git push

fatal: unable to access 'https://github.com/your_username/your_repository_name.git': Failed to connect to github.com port 443 after 21033 ms: Couldn't connect to server

This indicates that the Great Firewall is at work (sweat), here we only provide a solution if you have a VPN:

If you have proxy software running on your computer (such as Clash, v2ray, etc.), Git will not automatically use this proxy; you need to manually tell Git to use this proxy channel.

Check your proxy port number: Open your proxy software settings and find "Port" (usually the HTTP/S port is 7890, or 10809, depending on your software).

Set Git proxy in the terminal: Assuming your port is 7890 (if not, please change 7890 below to your port number), execute these two commands in the terminal:

git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

Then try pushing again:

git push
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.