The origin

What is the origin?

Git uses origin as the default name of a remote. Like with master for branches, origin is just a convention: you can call remotes whatever you want.

The interesting thing to note here is that Git, thanks to the --all option in the git log command, shows us that there are some more branches in the remote repository, but as you can see, they do not appear in the locally cloned one. In the cloned repository, there is only master.

But don't worry: a local branch in which to work locally can be created by simply checking it out:

[5] ~/grocery-cloned (master)
$ git checkout berries
Branch berries set up to track remote branch berries from origin.
Switched to a new branch 'berries'

Look at the message, Git says that a local branch has been set up to track the remote one; this means that, from now on, Git will actively track differences between the local branch and the remote one, notifying you of differences while giving you output messages (for example, while using the git status command).

Having said that, if you do a commit in this branch, you can send it to the remote and it will be part of the remote origin/berries.

This seems obvious, but, in Git, you can pair branches as you want; for example, you can track a remote origin/foo branch by a local bar branch, if you like. Alternatively, you can have local branches that simply don't exist on the remote. Later, we will look at how to work with remote branches.

Now, look at the log again:

[6] ~/grocery-cloned (berries)
$ git log --oneline --graph --decorate --all
* 6409527 (origin/master, origin/HEAD, master) Add a grape
* 603b9d1 Add a peach
| * a8c6219 (origin/melons) Add a watermelon
| * ef6c382 (HEAD -> berries, origin/berries) Add a blackberry
|/
* 0e8b5cf Add an orange
* e4a5e7b Add an apple
* a57d783 Add a banana to the shopping list

Now a green berries label appears, just near the red origin/berries one; this makes us aware that the local berries branch and remote origin/berries branch point to the same commit.

What happens if I do a new commit?

Let's try:

[7] ~/grocery-cloned (berries)
$ echo "blueberry" >> shoppingList.txt
  
[8] ~/grocery-cloned (berries)
$ git commit -am "Add a blueberry"
[berries ab9f231] Add a blueberry
Committer: Santacroce Ferdinando <[email protected]>

Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

git config --global user.name "Your Name"
git config --global user.email [email protected]

After doing this, you may fix the identity used for this commit with the following code:

git commit --amend --reset-author
 
1 file changed, 1 insertion(+)

As in the previous chapter, Git warns me about author and email; this time I will go with the suggested ones.

OK, let's see what happened:

[9] ~/grocery-cloned (berries)
$ git log --oneline --graph --decorate --all
* ab9f231 (HEAD -> berries) Add a blueberry
| * 6409527 (origin/master, origin/HEAD, master) Add a grape
| * 603b9d1 Add a peach
| | * a8c6219 (origin/melons) Add a watermelon
| |/
|/|
* | ef6c382 (origin/berries) Add a blackberry
|/
* 0e8b5cf Add an orange
* e4a5e7b Add an apple
* a57d783 Add a banana to the shopping list

Nice! The local berries branch moved forward, while origin/berries is still in the same place.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.145.114