I cloned a repo from github I made, I did some changes. My repo on github has 2 branches, main
and dev
. I want to push my changes to dev first and then main.
I ran:
git branch
while in the cloned (local) repo, giving me the output:
*main
I don't see my dev branch I made on github.
How can I push my changes to the dev branch?
CodePudding user response:
git branch
only shows local branches, to show remote branches use git branch -r
(to show local and remote branches, use git branch -a
).
You can push any local to branch to any remote branch, by specifying the source (local) and target (remote) branch:
git push origin main:dev
will push the commits on your local main branch to the remote dev branch in the repository "origin".
CodePudding user response:
you need to specify name of the branch
>git branch dev
>git add .
>git commit -m "your message"
>git push origin dev
CodePudding user response:
As knittl said, git branch
shows your branch names. Some other Git repository, such as the repository over on GitHub, will have its own branch names.
What's important in Git is not actually the branch names. These are for you, not for Git. More precisely, they exist so that Git can help you find the commits you want. This is because Git is really all about commits, not about branches—though we organize our commits into branches—and not about files, although each commit holds a snapshot of files.
This means that when you use Git, you must think first and foremost about commits. You need to know, at a sort of gut level, exactly what a commit is and does for you. Otherwise all the crazy things that Git does will be frustrating and impossible, and you will live in this xkcd comic.
Git is all about commits, so what is a commit? What does it do for you?
Each Git commit:
Is numbered. Each commit has a unique number, expressed as a hash ID (or object ID) in hexadecimal. This is the commit's true name, without which Git cannot find the commit. (For fun, see also the TV trope.) Hash IDs are large and ugly and impossible for humans to remember (or in most cases, pronounce