What is a `git push origin master`? Help with git refs, head and remotes

I have a question about what git push origin master does:

  • I know that origin is remote (aka GitHub)
  • git push origin master same as git push origin master_on_my_machine:master_on_github

I do not know if:

  • master_on_my_machine equals /refs/heads/master
  • master_of_github is /refs/remotes/origin/master

If it is equal, is it possible to do git push origin refs/heads/master:refs/heads/origin/master ?

Finally, I want to do only git push and git pull when:

  • I'm on the lead branch
  • I want to push and pull from my_test branch on github, just typing git push and git pull .
+47
git
Sep 05 '11 at 19:20
source share
2 answers

Git has two types of branches: local and remote . To use git pull and git push as you wish, you must tell your local branch ( my_test ) where the remote branch is tracking it. In typical Git mode, this can be done both in the configuration file and with commands.

Teams

Make sure you are on the master branch with

1) git checkout master

then create a new branch using

2) git branch --track my_test origin/my_test

and check it with

3) git checkout my_test .

You can then push and pull without specifying local and remote.

However, if you already created a branch, you can use the -u switch to tell Git push and pull that you want to use the specified local and remote branches from now on, like so:

 git pull -u my_test origin/my_test git push -u my_test origin/my_test 

Config

The remote branch tracking configuration commands are fairly straightforward, but I list the configuration method and it is also easier for me if I create a bunch of tracking branches. Using your favorite editor, open the .git/config project and add the following.

 [remote "origin"] url = git@github.com:username/repo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "my_test"] remote = origin merge = refs/heads/my_test 

Indicates a remote call to origin , in this case one GitHub style, and then tells my_test use it as a remote one.

You can find something very similar to this in the config after executing the above commands.

Some useful resources:

+32
Sep 05 2018-11-22T00:
source share

Or as one command:

 git push -u origin master:my_test 

Pushes commits from the local host branch to the (possibly new) remote branch my_test and configures master to track origin/my_test .

+11
Sep 05 2018-11-11T00:
source share



All Articles