Git commands data scientists use on a day-to-day basis

 Before you may ask why the heck am I still using command line Git in 2021, wait, I can explain! So yours truly is not the biggest fan of using the command line, especially when there are so many perfectly suited GUIs that exist out there.

Terms and Terminology

Scenario 1

git clone https://github.com/V-Sher/medium_demo.git
Figure 1: The highlighted text in blue is the remote URL for a repo.

Scenario 2

git branch
git checkout -b agenda
git push -u origin agenda
git rm fake_agenda.py
git reset -- fake_agenda.py
git checkout -- fake_agenda.py
git rm --cached fake_agenda.py
git commit -m "the file fake_agenda is gone from the repository"
git push -u origin agenda

Scenario 4

git checkout main
git pull
git checkout agenda
git checkout agenda
git merge main

Scenario 5

git add README.md
git commit -m "Apples and oranges issue averted"
git push

Scenario 6

print(“The agenda for this demo is as follows: Do A then B and finally C.”)
print(“The agenda for this demo is as follows: Do A and finally C.”)
git add agenda.py
git commit -m "Messing up the file by removing B's info"
Pick the latest commit id (on the right after `Latest commit’) for a file on Github
git checkout 3c8ebf0 -- agenda.py
git add agenda.py
git commit -m "Restoring B's info in the agenda"

Scenario 7

git branch -r
git checkout --track origin/featureB
git add featureB.py
git commit -m "Resolved conflict"
git push origin featureB

Scenario 8

Figure 2: The PR page on the Github Web UI. It contains information regarding the pull request-id and also the branch from which the PR was created.
git fetch origin pull/4/head:review_featureb1
git checkout review_featureb1

Scenario 9

git push -u origin <my_branch_name>
git push origin <remote_branch_name>

Scenario 10

git status
cd e_folder
touch .gitignore
vi .gitignore
# Ignore everything in this directory
*
# Except this file
!.gitignore
git status
git add e_folder
git commit -m "placeholder for images"
git push

Bonus Scenario 1

Bonus Scenario 2

git remote -v
git remote add origin_medium https://github.com/ABC/coworker_medium_repo.git
git remote add project1_origin http:github.com/XYZ/project1.gitgit remote add project2_origin http:github.com/MNO/project2.gitgit remote add project3_origin http:github.com/PQR/project3.git
git fetch origin_medium pull/PULL_REQUEST_ID/head:REVIEW_FEATURENAME
git checkout REVIEW_FEATURENAME
git fetch origin_medium new_agenda
git checkout new_agenda
git commit -a -m "Some input from V-Sher's end as well"
git push
git checkout agenda
git pull origin_medium second_agenda --allow-unrelated-histories

Parting words of wisdom

Congrats on making it this far…

Comments

Popular posts from this blog

Flutter for Single-Page Scrollable Websites with Navigator 2.0

A Data Science Portfolio is More Valuable than a Resume

Better File Storage in Oracle Cloud