Common
Init a repo or reinit a exist repo.
git init
Add the track files.
git add .
Commit the change:
git commit
git commit -m "the commit message"
Check the log ,you can input this command and see the commit hash.
git log --oneline
Branch
Switch the branch:
git checkout <new-branch-name>
This command creates a new branch based on your current branch (e.g., main) and switches to the new branch.
git checkout -b <new-branch-name>
Rename current branch:
git branch -m <new-branch-name>
Merged the branch and delete it
git branch -d <branch-name>
Completely roll back to a specific commit and delete any local changes after that commit.
git reset --hard <commit-hash>
Force-push this reset to GitHub:
git push --force origin main
Warning: Force-pushing rewrites history, so be cautious as this could affect other contributors.
Remote
Add a Remote Repo:
git remote add origin https://github.com/username/repo.git
Delete a Remote Repo:
git remote remove origin
Fetch it without touching your files
git fetch origin
Prefer your local changes:
git merge --allow-unrelated-histories -X ours origin/main
Prefer remote changes:
git merge --allow-unrelated-histories -X theirs origin/main

被折叠的 条评论
为什么被折叠?



