The most commonly used Git commands

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值