git在实际项目开发使用中的tips
git init
//初始化本地仓库git add .
//添加所有文件到暂存区git checkout -b feature-branch
//创建并切换到分支feature-branchgit push origin feature-branch:feature-branch
//推送本地的feature-branch(冒号前面的)分支到远程origin的feature-branch(冒号后面的)分支(没有会自动创建)删除本地和远程仓库的分支
git branch -D fix-udp-in-dog
git push origin --delete fix-udp-in-dog
- clone原仓库的主分支到本地:
git clone -b master
- 将本地仓库连接远程仓库:
git remote add matser git@github.com:val213/DragonOS.git
- 查看远程仓库的地址:
git remote -v
在将 Visual Studio 中的 C++ 项目推送到 GitHub 时,你应该在项目的根目录下初始化为代码仓库并进行推送。以下是详细步骤:
打开命令行终端:进入你的 C++ 项目所在的本地目录。
初始化本地仓库:在命令行中执行以下指令,将目录初始化为一个 Git 项目:
1
git init
这会在当前目录下创建一个名为
.git
的隐藏文件夹,其中包含了初始化的 Git 仓库中所有必须的文件。关联远程仓库:在项目根目录下,执行以下关联指令,将本地仓库与 GitHub 上的远程仓库关联起来:
1
git remote add origin 远程仓库地址
注意,执行成功后,先拉取远端仓库,执行拉取指令:
1
git pull origin master
这里需要设置拉取的分支信息,否则会提示: “There is no tracking information for the current branch.” 当前分支没有跟踪信息。
首次上传:将修改过的文件添加到暂存区域,执行添加指令:
1
git add .
然后将暂存区域的文件提交至本地仓库,执行提交指令:
1
git commit -m "commit msg"
最后将本地仓库推送至远程仓库,执行推送指令:
1
git push origin master
处理本地仓库分支与源代码仓库的冲突
To merge updates from theupstream
into your localuevent
branch, you can follow these steps:Fetch the updates from the
upstream
:1
git fetch upstream
Switch to your
uevent
branch:1
git checkout uevent
Merge the updates into your
uevent
branch. If the updates are on themaster
branch of theupstream
, you would do:1
git merge upstream/master
Replace
master
with the appropriate branch name if the updates are on a different branch.Resolve any merge conflicts if they exist. After resolving conflicts, you need to add the resolved files with
git add <file>
and then commit the changes withgit commit
.Finally, push the updates to your
uevent
branch on your remote repository:1
git push origin uevent
Replace
origin
with the name of your remote if it’s different.
- 设置上游仓库:git remote add upstream