<jupyter_start><jupyter_text>Scenario 1: INITIALIZE A REPOSITORY FROM EXSTING CODE If we have an existing project in our computer and we want the project to be tracked. We can follow these steps to initialize our local repo and push them to github.com<jupyter_code>git init<jupyter_output><empty_output><jupyter_text>This command would generate a .git directory in the folder where we execute this command. Output may come as bellow:<jupyter_code>Initialized empty Git repository in E:/OneDrive/_GitRepo/local_repo/.git/<jupyter_output><empty_output><jupyter_text>.git is a directory that contains all we need to track our codes, so if you don't want to track the project any more, you just type following command in the git bash<jupyter_code>rm -rf .git<jupyter_output><empty_output><jupyter_text>Step 1. ADD FILES  Before we add any files to the desired git repo we want ,we may want to check our project folder to see want we have now in our directory.and beacause we are initializing a repo from our existing code, so we are supposed to see a lot of files which is not added to our repo yet.<jupyter_code>git status<jupyter_output><empty_output><jupyter_text>The output comes as bellows:<jupyter_code>On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .idea
        NLP.py

nothing added to commit but untracked files present (use "git add" to track)<jupyter_output><empty_output><jupyter_text>Step 2. IGNORE FILES THAT WE DON'T WANT PEOPLE TO SEE<jupyter_code>vim .gitignore

# vim editor will be prompted, and we'll add following as to ignore the ".idea" file and python compiling files
.idea
*.pyc<jupyter_output><empty_output><jupyter_text>check the status<jupyter_code>git status<jupyter_output><empty_output><jupyter_text>See the ouput bellow:<jupyter_code>On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .idea
        NLP.py

nothing added to commit but untracked files present (use "git add" to track)<jupyter_output><empty_output><jupyter_text>Bellow is a map of how git works. After we use ```git init```in our local repo, we are now in the working directory. We've add nothing to be staged yet, but our code are now under tracking already. ![gitStatus.png](attachment:gitStatus.png)  Step 3. ADD FILE TO STAGING AREA<jupyter_code># add all files to the staging area
git add -A

# add specific file to staging area
git add filename

git status<jupyter_output><empty_output><jupyter_text>See the output as bellow:<jupyter_code>$ git add -A
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.


$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   NLP.py<jupyter_output><empty_output><jupyter_text>REMOVE FILES FROM STAGING AREA<jupyter_code>git reset
git reset NLP.py

git status
# next cell shows the output from the terminal
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        NLP.py

nothing added to commit but untracked files present (use "git add" to track)<jupyter_output><empty_output><jupyter_text>Step 4. COMMIT FILES<jupyter_code>git commit -m "First Commit"

git status
git log
[master (root-commit) e88052c] First commit
 2 files changed, 41 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 NLP.py<jupyter_output><empty_output><jupyter_text>Use ```git status``` and ```git log``` to see the modified history.<jupyter_code>$ git status
On branch master
nothing to commit, working tree clean

$ git log
commit e88052c8e597572234fe304f1c9c3d6301150b9c
Author: aukuno <<EMAIL>>
Date:   Thu Sep 28 12:41:02 2017 +0800<jupyter_output><empty_output><jupyter_text>After adding all the file to the local repo, you should `create` a repo on guthub.com. Then you shall use ```git remote add origin <EMAIL>:XiaohuiLee/myPyProj.git```to add the remote repo to be 'mirrored' as `origin` in your PC.  Step 5. PUSH FILES<jupyter_code>git push -u origin master
# Output
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 539 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:aukuno/testGit.git
   30235bd..e29273d  master -> master
Branch master set up to track remote branch master from origin.<jupyter_output><empty_output><jupyter_text>Scenario 2: CLONE A REMOTE REPO We use ```git clone```to clone a remote repo from github. We can specify the name and location of the cloned repo<jupyter_code>git clone <url> <where to clone>
git clone <EMAIL>:aukuno/testGit.git .
# the last dot means the current directory

git clone ../repo_to_be_cloned.git .
# the <url> can be local<jupyter_output><empty_output><jupyter_text>The output may come as bellow:<jupyter_code>Cloning into 'testGit'...
The authenticity of host 'github.com (172.16.58.3)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,172.16.58.3' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':(输入passphrase)
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), 4.12 KiB | 0 bytes/s, done.<jupyter_output><empty_output><jupyter_text>VIEWING INFORMATION ABOUT REMOTE REPOSITORY<jupyter_code>git remote -v

# list all the branch of the repo, no matter local or remote 
git branch -a<jupyter_output><empty_output><jupyter_text>Output:<jupyter_code>origin  <EMAIL>:aukuno/testGit.git (fetch)
origin  <EMAIL>:aukuno/testGit.git (push)

    
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master<jupyter_output><empty_output><jupyter_text>PUSHING CHANGES First we need to commit changes like we did previously, then we push:<jupyter_code># commit changes locally
git diff
git status
git add -A
git commit -m "delete 4test.txt"<jupyter_output><empty_output><jupyter_text>Output:<jupyter_code>On branch master
Your branOutputch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    4test.txt
        modified:   Use_git_under_2_scenarios.ipynb

no changes added to commit (use "git add" and/or "git commit -a")<jupyter_output><empty_output><jupyter_text>After we commit, all the modification is written to the local repo. Then, we should pull from remote repo beacause there may be modifications done by other developers on the remote branch.<jupyter_code># push
git pull origin master 
git push origin master<jupyter_output><empty_output><jupyter_text>Output:<jupyter_code>$ git pull origin master
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
From github.com:aukuno/testGit
 * branch            master     -> FETCH_HEAD
Already up-to-date.

$ git push origin master
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 166.45 KiB | 0 bytes/s, done.
Total 9 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To github.com:aukuno/testGit.git
   e601bba..de26688  master -> master<jupyter_output><empty_output><jupyter_text>CREATE A BRANCH FOR DESIRED FEATURES 切换branch——>修改文件——>添加修改——>确认修改——>push到远程branch（此时远程branch会自动生成branch以追踪本地branch[名字相同]）<jupyter_code>git branch newBranch
git chechkout newBranch


# 我们可以把这个生成分支的过程看成是在本地仓库里操作的，切换也只是在本地上切换，
# 只有到了最后将所有修改commit到本地仓库后，在push到远程仓库时，
# 远程仓库才会生成newBranch这个分支<jupyter_output><empty_output><jupyter_text>After we did some sort of modification to our files, we need to use ```git add -A``` and ```git commit```to save the changes to local repo. As for now ,the change still have no effect on the remote repo. We will use ```git push ```to push the changes we've done on branch ```newBranch```to the remote repo.<jupyter_code>git push -u origin newBranch
git branch -a<jupyter_output><empty_output><jupyter_text>Output:<jupyter_code>$ git push -u origin newBranch
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
Everything up-to-date
Branch newBranch set up to track remote branch newBranch from origin.


$ git branch -a
  0-a
  master
* newBranch
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/newBranch<jupyter_output><empty_output><jupyter_text>MERGE A BRANCH TO THE "MASTER" BRANCH<jupyter_code>git checkout master

# pull the latest version of master
git pull origin master

# show the merged branches on the local repo
git branch --merged

# merge branch newBranch
git merge newBranch

# update the remote master branch
git push origin master<jupyter_output><empty_output><jupyter_text>Output:<jupyter_code>$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

Aukuno@Foxrail MINGW64 /e/OneDrive/_GitRepo/testGit (master)
$ git pull origin master
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
From github.com:aukuno/testGit
 * branch            master     -> FETCH_HEAD
Already up-to-date.

Aukuno@Foxrail MINGW64 /e/OneDrive/_GitRepo/testGit (master)
$ git branch --merged
  0-a
* master

Aukuno@Foxrail MINGW64 /e/OneDrive/_GitRepo/testGit (master)
$ git merge newBranch
Auto-merging Use_git_under_2_scenarios.ipynb
Merge made by the 'recursive' strategy.
 Use_git_under_2_scenarios.ipynb | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Aukuno@Foxrail MINGW64 /e/OneDrive/_GitRepo/testGit (master)
$ git push origin master
Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 538 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:aukuno/testGit.git
   ef2b944..831496c  master -> master<jupyter_output><empty_output><jupyter_text>You can use ```git branch -a``` again to solidate that the merge is successful. After the merge and push is completed, branch ```newBranch``` is no more needed, so we need to delete them.<jupyter_code>$ git branch -a
  0-a
* master
  newBranch
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/newBranch<jupyter_output><empty_output><jupyter_text>DELETE A BRANCH LOCALLY AND REMOTELLY<jupyter_code># delete local repo
git branch -d newBranch

# delete remote repo
git push origin --delete newBranch<jupyter_output><empty_output><jupyter_text>Output:<jupyter_code>Enter passphrase for key '/c/Users/Aukuno/.ssh/id_rsa':
To github.com:aukuno/testGit.git
 - [deleted]         newBranch<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09244288224956063, 'fraction_numerical': 0.02170474516695958, 'mean_word_length': 4.915280665280665, 'pattern_counts': {'":': 0, '<': 136, '<?xml version=': 0, '>': 148, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '30', 'dir': 'jupyter-structured-clean-dedup', 'id': '405347', 'license': 'Apache-2.0', 'n_tokens_mistral': 4113, 'n_tokens_neox': 3861, 'n_words': 1315, 'path': 'Two Common Scenarios Using Git.ipynb', 'repo_name': 'aukuno/testGit', 'size': '11421'}