首页 > 解决方案 > 如何使用 GIT 将我的代码从本地机器推送到除 master 之外的不同分支中的 Azure devops?

问题描述

如何使用 GIT 将项目文件夹从我的本地计算机添加到 Azure 上的 git 存储库?

在项目根目录的本地目录中

git init

git remote add origin <URL for Azure Git repo>

git add .

git commit -m 'initial commit'

git push -u origin master

在对堆栈溢出进行基本研究后,我知道这些命令,但我的问题是,如果我们有一个名为“ dev ”的分支,并且我在该分支中创建了一个名为“ sandbox ”的文件夹,那么如果我想在其中添加我的项目我可以通过转到该文件夹​​复制 https 链接以及应输入的内容来完成特定文件夹

git push -u origin master

而不是大师?我必须写“ dev ”,因为这是我将要推送我的代码的分支吗?

标签: gitazuregithubazure-devops

解决方案


要推送到原始开发,您可以这样做

git push -u origin dev

一个快速的 git 教程

我将解释如何创建 git repo、创建新分支、设置上游并将分支推送到远程。

初始化一个 git repo 并在 master 中进行一些虚拟提交

# init a git repo
git init 

# Add a remote for the git repo
git remote add origin <URL for Azure Git repo>

# create a dummy file
touch file1

# stage all changes made to git repo so they can be commited
git add .

# make a commit for the staged changes
git commit -m 'initial commit'

# push commit to remote 
git push

# The same as previous step, buy done explicitly by specifying the remote address and branch name 
git push -u origin master

在新分支中添加演示提交

# create a new file
touch file2

# stage changes
git add .

# decided to push these changes to dev instead of the master branch
# create a new branch and checkout to dev
git checkout -b "dev"

# make commit to the dev branch
git commit -m 'dev commit'

# push the changes
git push

# or

# Only push the changes of dev to remote address origin
git push -u origin dev

最后你的 git log 看起来像这样(带有漂亮的打印和格式)

* 2e48c23 - (HEAD -> dev, origin/dev)
|           dev commit - clmno
* fad2e5b - (master, origin/master)
            initial commit - clmno

推荐阅读