Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push changes to branch?

Tags:

git

github

Can you explain me how to use git in case, when I have access to repository:

  • How to download repository
  • How to push changes in selected branch
  • How to select branch to push

I tried these steps

git init
git clone git.repository
git pull develop  (where develop is branch)
git add .
git commit -m "m"
git push origin develop

Result is:

* branch            develop    -> FETCH_HEAD
fatal: refusing to merge unrelated histories

What I do wrong?

like image 845
Darama Avatar asked Mar 15 '17 21:03

Darama


People also ask

How do I push to a branch?

Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.

How do I push changes to my remote branch?

In case you are using the Tower Git client, pushing to a remote is very easy: simply drag your current HEAD branch in the sidebar and drop it onto the desired remote branch - or click the "Push" button in the toolbar.

How do you push changes to someone else's branch?

Push Branch to Another Branch In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.


2 Answers

3 Steps to Commit your changes

Suppose you have created a new branch on GitHub with the name feature-branch.

enter image description here

FETCH

    git pull --all         Pull all remote branches
    git branch -a          List all branches now

Checkout and switch to the feature-branch directory. You can simply copy the branch name from the output of branch -a command above

git checkout -b feature-branch

VALIDATE

Next use the git branch command to see the current branch. It will show feature-branch with * In front of it

git branch   check current branch
git status   check the state of your codebase       

COMMIT

git add .   add all untracked files
git commit -m "Rafactore code or use your message"

Take update and the push changes on the origin server

 git pull origin feature-branch
 git push origin feature-branch

OR you can rebase with the master before commit

git fetch
git rebase origin/master
git push origin feature-branch
like image 125
Hitesh Sahu Avatar answered Sep 18 '22 13:09

Hitesh Sahu


How to download repository

# download a repository
git clone <url>

How to push changes in selected branch

# push changes to remote branch
# assuming you are on the master branch right now
git push origin master

How to select branch to push

 # push any desired branch to remote
 git push -u origin local_branch_name:remote_branch_name
like image 21
CodeWizard Avatar answered Sep 17 '22 13:09

CodeWizard