如何将更改推送到分支?

Dar*_*ama 5 git github

当我有权访问存储库时,您能否解释一下如何使用git:

  • 如何下载资料库
  • 如何推送所选分支中的更改
  • 如何选择要推送的分支

我尝试了这些步骤

git init
git clone git.repository
git pull develop  (where develop is branch)
git add .
git commit -m "m"
git push origin develop
Run Code Online (Sandbox Code Playgroud)

结果是:

* branch            develop    -> FETCH_HEAD
fatal: refusing to merge unrelated histories
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

Hit*_*ahu 12

提交更改的 3 个步骤

假设您在 GitHub 上创建了一个名为feature-branch的新分支

在此处输入图片说明

拿来

    git pull --all         Pull all remote branches
    git branch -a          List all branches now
Run Code Online (Sandbox Code Playgroud)

签出并切换到功能分支目录。您可以简单地从上面的 branch -a 命令的输出中复制分支名称

git checkout -b feature-branch

证实

接下来使用 git branch 命令查看当前分支。它将在前面显示带有 * 的特征分支

git branch   check current branch
git status   check the state of your codebase       
Run Code Online (Sandbox Code Playgroud)

犯罪

git add .   add all untracked files
git commit -m "Rafactore code or use your message"
Run Code Online (Sandbox Code Playgroud)

在源服务器上进行更新和推送更改

 git pull origin feature-branch
 git push origin feature-branch
Run Code Online (Sandbox Code Playgroud)

或者您可以在提交之前使用 master 进行 rebase

git fetch
git rebase origin/master
git push origin feature-branch
Run Code Online (Sandbox Code Playgroud)


Cod*_*ard 9

如何下载存储库

# download a repository
git clone <url>
Run Code Online (Sandbox Code Playgroud)

如何推送所选分支中的更改

# push changes to remote branch
# assuming you are on the master branch right now
git push origin master
Run Code Online (Sandbox Code Playgroud)

如何选择要推送的分支

 # push any desired branch to remote
 git push -u origin local_branch_name:remote_branch_name
Run Code Online (Sandbox Code Playgroud)