042_how_to_connect_your_local_repository_to_remote_repository
Create a local repository
Create a remote repository on the Github
Let's connect them, and let's see what internally happens
Let's also see what internally happens when you perform "push"
======================================================================
# Create local repository named repo
git init repo
cd repo
======================================================================
vim f1.txt
a
git add f1.txt
git commit -m "1"
======================================================================
Create a remote repository named repo on Github
Copy SSH address of your remote repository
======================================================================
# remote has functionalities related to remote repository
# add: connects remote repository to local repository
# origin: name of remote repository you will use
git remote add origin ssh_address_of_remote-repository
======================================================================
go to gistory
data about remote named "origin" is stored in ./.git/config
address of "origin" is stored in url
when you bring data, where will you bring data from your remote repository,
and where will you store that data to in your local repository
======================================================================
# Check current branch
git branch
* master
# Let's try to push "tasks" you did in the local repository into the remote repository
git push
# Meaning: current branch named "master" has no upstream branch,
# so you need to run
# origin: repository
# master: branch
git push --set-upstream origin master
upstream: can be considered as remote repository which is connected to local repository
======================================================================
Above command does 2 following:
1. master branch of local repository is connected to master branch of remote repository
1. upload codes
======================================================================
./.git/config file has been changed
branch called "master" is newly stored.
======================================================================
refs/remotes/origin/master file has been created
======================================================================
refs/heads/master contains information of master branch of local repository
======================================================================
Commit which is pointed by refs/heads/master file
======================================================================
# --decorate: to see detailed infomation
# --graph: to see information in illustration
git log --decorate --graph
"Current branch master in local repository"
and "master branch in remote repository" which is connected to local master branch
are pointing to same commit
======================================================================
vim f1.txt
a
b
git commit -am 2
vim f1.txt
a
b
c
git commit -am 3
======================================================================
git log --decorate --graph
In local repository had performed "2 number of commits"
Since you're before "push", origin/master branch has still "1 commit"
How about infomation can be told to you?
It's because git stores relevant data
======================================================================
commit which is pointed by ./.git/refs/heads/master file
commit which is pointed by ./.git/refs/remotes/origin/master file
======================================================================
git push
you will not see "you should perform set stream command"
because you connected 2 branches of local and remote repositories
======================================================================
Commit which is pointed by ./.git/refs/remotes/origin/master file
======================================================================
git log --decorate --graph