Vibe Coding Must Learn Git Skill
日月小楚|12月 12, 2025 13:17
Even if AI can handle projects, there are still some skills that must be learned. The most basic one is Git.
If you have worked as the second party, you must have worked on the first and second versions The final version, will never be revised, and if it is changed again, it will be a puppy version. And ultimately chose the first version.
Now, even though AI has become the good tempered person who works tirelessly to make changes. You still need to manage various versions, and this is the core function of Git. Simply put, once you Git, make a new backup of your current code.
Git is a must-have skill for programmers, as it can also prevent AI from modifying code, creating branches, and pushing GitHub with just one click.
Of course, in the era of AI, most of it can be operated by AI. What we need is a basic understanding of it and mastery of its core functions.
──────────────
🛠️ 1. Initial configuration of Git
Download Git, and after downloading from the official website, you can default to the next step along the way
• Configure username and password
git config --global http://user.name
git config --global http://user.email
After configuration, you can view on the terminal:
git -v
git config --list
──────────────
📂 2. Initialize the project
To run Git for the first time in a project, you need to initialize Git first.
Method 1:
Open your project folder in the cursor.
Open the integrated terminal (View>Terminal or Ctrl+`).
Run command: git init. This will create a. git folder in the project to initialize the local repository.
• (Optional) Connect to a remote repository (such as GitHub): Run git remote add origin https://github.com/ Your username/repository name. git. If you don't have a remote repository, create it on GitHub first.
Method 2:
In the cursor, select initialize Repository directly on the Git page
──────────────
💾 3. GIT submission version, view version changes
3.1 Add and Submit Changes (Management Version):
After editing the code, click on the source control icon (which looks like a branch symbol) in the left sidebar of the cursor.
In the Source Control panel, you will see a list of changed files. Click the+icon next to the file to temporarily save (Stage) changes, or click the+icon at the top to temporarily save all.
Write a description in the submission message input box (such as "Add login function"). The AI function of cursor can help generate messages: click on the flashing icon next to the input box( ✨), AI will automatically generate commit messages based on changes and history (supporting Conventional Commits style).
Click the 'commit' button or run git commit - m 'message' to commit. This creates a new version.
Repeat this process, submitting each small change once to maintain atomicity.
When committing for the first time, a pop-up appears and the option 'Always' is selected
3.2 Viewing different versions
Recommendation: In the source contrast graph, you can view the saved versions and see the changes for each file
View through command: Run git log on the terminal (displaying all commit history, including ID, author, and messages). Simplify the display using git log -- oneline, or git show<commit ID>to view detailed changes for a specific version.
To view a specific version of a file: right-click on the file>Open Timeline, or run git flame<filename>to view the commit source for each line of code.
Compare versions: In the source control panel, select two submissions, right-click>Compare Changes to view differences
──────────────
⏪ 4. Rollback/Recovery
4.1 Revoking changes that have not been committed
The modifications in the cursor include restore, which can be restored for a single modification
On the source control page, for modifications made since the last commit, click on the discard changes next to the file name to directly roll back to the state of the last commit
Operate through the cursor interface:
Open the left source control panel (Ctrl+Shift+G)
• Find the modified file in the "Changes" area
Right click on the file and select 'Discard Changes'
• Or click on the undo icon next to the file "↶"
Through the command panel:
Press Ctrl+Shift+P to open the command panel
• Enter Git: Discard All Changes - undo all changes
• Enter Git: Discard Changes - undo changes to selected files
Through terminal commands:
Git restore<filename>(undo changes to individual files)
Git restore. (undo all file changes)
Git restore<directory>/* (undo changes in a specific directory)
4.2 Rollback and Recovery of Submission History
The temporary storage area is a buffer that allows you to carefully select and prepare the changes to be recorded before submission. Staged Changes
When the cursor submits a commit, it will automatically add all the files in your 'Changes' list to the temporary storage area, and then immediately execute the commit.
Commit id can be obtained by right clicking on the version in the source contrast graph.
(1) Hard rollback (completely deleting changes)
⚠️ Warning: Hard rollback will permanently delete changes, please use with caution
Git reset -- hard will fully restore your project folder (including all. py files) to the old version state you specified, and will delete all version records after that.
Using Git Graph:
Right click on the target commit → "Reset current branch to this commit" → select "Hard"
Through the terminal:
git reset --hard <commit-id>
Git reset -- hard 9fd5c20c1e9d9ca6ebce4edc2bb897e441d181 (hard rollback to specified commit)
Git reset - hard HEAD~1 (hard rollback to the previous commit)
(2) Use Revert (recommended for pushed submissions)
Revert does not delete history, but creates a new submission whose content happens to be used to offset the changes made by an old submission.
Git revoke<commit hash>(Create a reverse commit to undo changes)
Git revoke HEAD (undo recent commit)
Git revoke<start commit>..<end commit>
(3) Soft rollback (keep changes in working directory)
Restore the commit to the previous or specified one, but the modified content remains unchanged.
Its core function is to simply move the repository pointer (HEAD) to the old version you specify, without changing the code you have already written (working directory) and the content already added to the staging area. Simply put, it means revoking the commit.
Used for too many commits, merging multiple messy commits.
Using Git Graph extension:
Install the Git Graph extension
Click the "Git Graph" button in the source control panel
Right click on the target submission and select 'Reset current branch to this commit'
Select 'Soft' mode
Through the terminal:
git reset --soft <commit-id>
Git reset - soft HEAD~1 (soft rollback to the previous commit)
(4) Mixed rollback (keep changes but cancel temporary storage)
Git reset<commit ash>(mixed rollback, default mode)
Git reset HEAD~1 (rollback to previous commit)
4.3 Branch level rollback and recovery
Recovery after deleting local branch
Git Reflog (View references to deleted branches)
Git branch<branch name><commit hash>(Restore deleted branch)
Recovery after forced push
Git reflog show origin/<branch name>(view remote reference logs)
Git reset -- hard<previous commit>(restore to previous state)
git push --force-with-lease
──────────────
🌿 5. Branch
They are extremely lightweight and inexpensive operations in Git, so be bold in creating branches for every new task, idea, and bug fix. This is the path to efficient and secure development.
By default, a Git repository will have a main branch during initialization, typically named 'main'.
The role and advantages of branches:
Parallel development: Different functions/fixes are independent of each other and do not interfere with each other.
Experimental isolation: Try new solutions without affecting stable code.
Code review and release: Merge PR/MR into the backbone and trigger CI/CD.
• Rollback and Tracking: The commit history of each branch is clear, making it easy to locate and roll back.
Technically speaking, a branch is not a complete copy of a project folder, which would be a waste of space. A branch is essentially a lightweight, movable pointer that points to a specific 'commit'.
The main branch is a pointer that usually points to the latest and most stable submission of the project.
When you create a new branch, you simply create a new pointer that points to the same place as the submit pointer you are currently in.
View the branch in the bottom right corner of the cursor
Git branch (view all local branches, the current branch will be marked with an *)
Git branch-a (View all branches, including those from remote repositories)
Create a branch in the bottom right corner of the cursor
2.1 Create a branch from the current point
Git branch feature payment (create a new branch called feature payment, but the person is still in the current branch)
git checkout -b feature-payment ( ✨ Highly recommended: Create and immediately switch to a new branch, one step at a time)
2.2 Create a second branch from the specified point?
Used to create several different branch directions, assuming you are currently in another branch but want to start a new job from the latest state of main:
git checkout -b test2 main
Using commit ID (hash value): the most accurate way.
git checkout -b test3 87be5a4304950ba71c375fdb785e44d3ac2dc7c7
Switch the branch git switch test2 in the bottom right corner of the cursor (this is an updated and more recommended command because its semantics are clearer and only used for switching)
After switching from working on a branch to a branch, all your git add and git commit operations only apply to the current branch.
(On the feature payment branch)
... write code ..
git add .
git commit -m "feat: add payment processing logic"
When you complete the development on the branch, you need to merge the results back into the main line.
Firstly, switch back to your target branch (usually the main branch)
git switch main
2. Pull the latest remote code to ensure that your main branch is in the latest state (good habit)
git pull
3. Execute the merge command to merge the changes made to the feature payment branch
git merge feature-payment
Method 2:
Switch to the target branch.
• Source control>"...">"Branch">"Merge" Select the source branch.
Regarding Merge Conflict: If Git discovers during a merge that you have made different modifications to the same line of code in the same file on the main branch and feature payment branch, it will not know who to listen to, and a "conflict" will occur. You need to manually open that file, resolve the conflict (decide which code to keep), and then add and commit to complete the merge.
After deleting branches and merging them, they can usually be deleted to keep the warehouse clean.
Git branch - d feature payment (delete a merged local branch, - d is an abbreviation for -- delete, which is relatively safe)
Git branch - D failed experiment branch (if the branch has not been merged yet, but you are sure you want to forcibly delete it, such as a failed experiment, use - D)
Collaborate with remote warehouses
Git push - u origin feature payment (push your new branch to a remote repository, such as GitHub, so that others can also see it)
Git push origin - delete feature payment (deleting branches on a remote repository, usually done after merging into main and pushing to the remote)
──────────────
☁️ 6. GitHub Remote
6.1 First operation of warehouse
First setup: Associate local projects with a GitHub repository.
Create a new repository on the GitHub website: • Open the GitHub official website and log in to your account. Click on the+sign in the upper right corner and select New repository. Give the warehouse a name (usually the same as the name of your project folder). Do not check "Add a README file", "Add. gitignore", or "Choose a license" as we already have them locally. Click on 'Create repository'.
Local association: After creating a repository, GitHub will display a page with several lines of commands. Find the section titled '... or push an existing repository from the command line' and copy the command there. Usually it goes like this:
echo "# test2" >> http://README.md
git init
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/ishicm/test2.git
git push -u origin main
Method 2:
In the south contract, there is a push function. When pushing for the first time, you will be asked to associate relevant content by simply filling in the link to the repository, for example https://github.com/ishicm/test2.git
The process of going from an existing GitHub repository to a local one is simpler.
(1) Copy repository address on GitHub:
Open the GitHub repository page you want to synchronize.
Click on the green<>Code button.
Copy HTTPS or SSH addresses.
(2) Clone repository in cursor:
Method 1 (via the welcome page): Open a new cursor window, select clone directly on the welcome page, and then paste the address you copied.
Method 2 (via command panel): The cursor will automatically download the entire project to your computer. Now, the local and remote connections have been established.
6.2 Second and subsequent warehouse operations
Push:
commit
push。 Method 1: In the source control of cursor, there are multiple places that can be synchronized, including sync changes that appear after commit. Method 2 in the bottom left corner: Enter git push in the terminal.
Pull:
In the bottom left corner of the cursor's source control, there is an update button directly.
Then it can be divided into two situations:
Scenario 1: If the local position has not been changed, the latest version will be downloaded directly
Scenario 2: If there are changes to the local code, there may be conflicts. (PS: Check the information again when encountered)
Share To
HotFlash
APP
X
Telegram
CopyLink