Git wants to be configured. The above commands add syntax to ~/.gitconfig
Initialize Repo
I easily Initialize Repo with the git init command:
mkdir ~/danapp1
cd ~/danapp1
git init
Clone Repo
I Clone a Repo to get a clone (copy) of a Repo:
cd ~
git clone https://github.com/tensorflow/tensorflow
The above command gives me folder named tensorflow full of tensorflow software.
Fork Repo
When I Clone a Repo to my laptop I get a Clone.
When I Clone a Repo to a server (like github.com) I get a Fork.
To Fork tensorflow-Repo I login to github.com
Then I load this URL:
https://github.com/tensorflow/tensorflow
Next, I click the Fork-button in upper right.
If I want to add code to a Repo, I fork it; otherwise I just clone it.
Branch Repo
I Branch a Repo to get a Branch of a Repo:
cd ~
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
git checkout -b danbranch1
mkdir tensorflow/examples/tutorials/bikle
echo This folder should create demos by Dan > tensorflow/examples/tutorials/bikle/readme.txt
Above, I create a Branch called danbranch1.
The code in danbranch1 is separate from the code in the Branch called master.
Commit Repo
Commit is like the save button in an editor.
mkdir ~/danapp2
cd ~/danapp2
echo danapp2 should be an enhancement of danapp1. > readme.txt
git init
git add .
git commit -am 'danapp2 has enhanced danapp1'
When I Commit, I should give a reason for the commit.
Fetch Repo
I Fetch a Repo to access Commits in that Repo:
mkdir ~/danapp10
cd ~/danapp10
echo danapp10 should be an enhancement of danapp2. > readme.txt
git init
git add .
git commit -am 'danapp10 has enhanced danapp2'
cd ~
git clone danapp10 danapp11
cd ~/danapp10
echo danapp11 is a clone of danapp10 >> readme.txt
git commit -am Another_Enhancement
cd ~/danapp11
git fetch
git fetch tells danapp11 about Another_Enhancement Commit in danapp10.
That Commit, however, has not been Merged into danapp11 yet.
That Merge can happen next if I want.
Merge Repo (Fetch)
After a Fetch, I Merge a Repo to merge a commit from another Repo:
cd ~/danapp11
git merge
That Merge makes danapp11 identical to danapp10
Merge Repo (Branch)
Another type of Merge is to Merge a Branch:
cd ~/danapp10
git checkout -b danbranch1
echo Use danapp10 to test Branches >> readme.txt
git commit -am 'I like this commit.'
git checkout master
git merge danbranch1
That Merge makes master identical to danbranch1.
Pull Repo
I Pull a Repo if I want to Fetch and Merge:
git clone ~/danapp10 ~/danapp12
cd ~/danapp10
echo danapp10 more interesting. >> readme.txt
git commit -am 'I like this commit 2.'
cd ~/danapp12
git pull
That Pull makes danapp12 identical to danapp10.
Push Repo
I Push a Repo to copy Commits to a server:
cd /tmp/
git clone git@github.com:danbikle/ml4us.git
cd ml4us
echo Hello >> README.md
git commit -am 'Dan was here.'
git push
That Push copies a Commit to the server.
If I want to copy a Commit between two Repos on the same host, I should use Pull not Push.
If I want to copy a Commit between two Repos on the different hosts, over ssh, I should use Pull not Push.
Log
I use Log to list recent Commits:
cd /tmp/
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
git log -9
Grep Repo
I Grep Repo to search for text:
cd /tmp/
git clone https://github.com/scikit-learn/scikit-learn
cd scikit-learn
git grep rbm.learning_rate