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. Prepare Environment Dependencies#

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

2. Start Building#

Step One: Clone the Code#

git clone URL
cd folder_name

Step Two: Build (Package)#

npm run build

Step Three: 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 includes debugging information. If everything is correct, 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 One: Prepare GitHub Repository#

  1. Log in to your GitHub.
  2. Create a new repository. (No need to check to add a README file, add .gitignore, or add a license, as this is a forked project with existing files).
  3. Remember your repository name.

Step Two: Connect and Push from Local Terminal#

Now, return to your VS Code or command line window (ensure the path is at the root 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 the repository 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 you encounter the error "fatal: remote origin already exists" when executing step 5, it means you may have tried to link before (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 Three: 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 follow three steps:

1. "Package" the modifications#

git add .

2. Label the package (this step is crucial, it may take a while to load)#

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

(After executing this, you should see a list of modified or deleted file names 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 means you may have forgotten to add or commit.
However, 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 the solution if you have a VPN:

If you have proxy software running on your computer (like 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, replace 7890 below with 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.