In Git 1.7.0 and later, you can checkout a new branch:
git checkout -b <branch>
Edit files, add and commit. Then push with the -u (short for --set-upstream) option:
git push -u origin <branch>
Git will set up the tracking information during the push.
Answer from Daniel Ruoso on Stack OverflowIn Git 1.7.0 and later, you can checkout a new branch:
git checkout -b <branch>
Edit files, add and commit. Then push with the -u (short for --set-upstream) option:
git push -u origin <branch>
Git will set up the tracking information during the push.
If you are not sharing your repo with others, this is useful to push all your branches to the remote, and --set-upstream tracking correctly for you:
git push --all -u
(Not exactly what the OP was asking for, but this one-liner is pretty popular)
If you are sharing your repo with others this isn't really good form as you will clog up the repo with all your dodgy experimental branches.
Push to remote repository
How to properly push local branch to remote branch?
How to create a branch on remote and push to it?
Pushing a local merged branch to the remote main branch
Videos
TL;DR How to push changes in branch_a from local repo to contents of branch_a on remote repo?
Hi all. In my local repo, I have a branch ("branch_a") and have made commits to a file inside that branch. How do I push these changes to my remote repository? My remote repository already contains this branch (as well as all files inside). Will git push be smart enough to push these changes to "branch_a" in my remote repo? Or will it push the changes into my remote repo master branch instead?
Here is the output of cat .git/config:
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git@gitlab.example.net:username/redirects-horizon-homes.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "branch_a"]
remote = origin
merge = refs/heads/branch_aThanks in advance.