KEMBAR78
Git Init (Introduction to Git) | PDF
$ git init
Intro to Git and GitHub
Big thanks to Krish Chowdhary (GDSC Alumni) for allowing us to re-use some of his old slides!
If you haven’t already installed it… (~8 min)
Creating GitHub Account: github.com/join
Download Git for...
Windows: git-scm.com/download/win
Linux:
● sudo apt install git-all (if you use a Debian-based Linux)
● OR sudo dnf install git-all (if you use a Red Hat-based Linux)
MacOS:
● git-scm.com/download/mac
● OR type brew install git in your terminal (if you have homebrew)
Some icebreaker questions in the meantime
1. What year are you in?
2. What POSt are you in or planning on pursuing?
3. Have you ever used Git before?
4. What is your favourite programming language?
5. Any questions for us? 😄
What is Git?
Collaboration
Version control
More
● Git is a version control system
● A software that you interact with through your
terminal/command line
● Allows you to keep track of changes made to
your project
● Facilitates effective collaboration for multiple
individuals working on one project
Ever done something like this?
A better way? use Git
GitHub
● A website that is the central location on the internet
where you push (upload) and pull (download) code from
● From there people can view the project and its version
history and starting contributing to it
● Think of it as a super advanced Google Drive
● Let’s take a look at an example GitHub repository:
github.com/utmmcss/mcss-website-frontend
● Repository: the collection of all the versions of the files in a
project
●
What is GitHub?
Git != GitHub
Git is a command line tool. GitHub is a website
GitHub Diagram
Milind’s PC
Daniel’s PC Nivy’s PC
GitHub
Let’s git started.
Hands-on activity: forking and clon(e)ing (~5min)
Your task:
1. Visit github.com/Daniel-Laufer/GDSCUTM-git-workshop
2. Click the “Fork” button
○ This will create a copy of this repository where your GitHub account is the owner
3. Then in your terminal (on your local computer) type: git clone <your forked repository url>.git
○ This will essentially download your repository from GitHub to your computer
4. Type: ls (first letter is a lowercase ‘L’). This command lists out everything in your current directory
○ You will see a new directory listed (aka a folder)
5. Type: cd <the name of this new directory> to “move” into that directory
Don’t forget the .git suffix
Remove the “<>” before using
Version control basics with Git
1. Staging & Committing
1. Staging & Committing
edit
1. Staging & Committing
edit save
1. Staging & Committing “Main” git branch
Initial
commit
1. Staging & Committing
edit
“Main” git branch
Initial
commit
1. Staging & Committing
edit save
Initial
commit
“main” git branch
1. Staging & Committing
edit save
add
“main” git branch
Initial
commit
1. Staging & Committing
edit save
commit
add
“main” git branch
Initial
commit
New
commit
Hold up… what’s a commit again?
It’s simply a change to your project that git records in its
version history.
Staging & Committing
1st
commit
2nd
commit
Staging & Committing
1st
commit
2nd
commit
3rd
commit
Staging & Committing
3rd
commit
4th
commit
2nd
commit
1st
commit
1. Staging & Committing
Initial
Save
New
Save
New
Save
New
Save
New
Save
Staging & Committing
1st
commit
2nd
commit
3rd
commit
4th
commit
5th
commit
Hands-on activity: adding & committing (~5 min)
Instructions (ensure you are in the directory we downloaded last time)
1. Type git status
○ Git should tell you that everything is up to date
2. On your computer, make a change to any of the files and save that file
3. Now again type git status
○ You should see that git saw the change you just made
4. Type git add <your filename>
○ This will “stage” or in other words “prepare” your file for commiting
5. Type git commit -m “<whatever message you want goes here :)>”
○ This will tell git to “save” your file modifications in its version history
6. Type git log to see a list of your recent commits
7. (Optional) type git push to “push”, or in other words upload, your changes to your github
Hands On!
10 minutes
$ cd into the repository
$ Open index.html and
make some changes
$ git status
$ git add index.html
$ git commit -m “msg”
$ git log
Git Branching and Merging
Git branches
● Think of Git’s version history as a tree (the weird CS type of tree)
● Git branches are basically “independent lines/sections of
development”
c2
c1
c5
c3 c4
Branch #1
Branch #2
Why use Branches?
Example: a different branch used for different versions
of a codebase
c2
c1
c5
c3 c4
“main” branch
“dev” branch
Another example
Using a separate branch to develop a new feature.
c2
c1
c5
c3 c4
“main” branch
“create_cat_pic_api” branch
How are branches used? Continued
Example: a different branch used for different versions
of a codebase
c2
c1
c5
c3 c4
“Production” branch
“Development” branch
Branches
Initial
Commit
2nd
Commit
3rd
Commit
4th
Commit
5th
Commit
2. Branches
main
new branch
2. Branches
main
new branch
2. Branches
main
new branch
2. Branches
main
new branch
Merging
● To “merge” your current branch with
another you use the command git
merge <other branch name>
● Git will intelligently combine all changes
from that one branch with another
● foreshadowing: Git might have some
trouble doing this sometimes :(
Merging
main
new branch
Merging
main
new branch
Hands-on activity: Branching and Merging
Instructions (ensure you are in the directory we used last time)
1. Type git branch
○ This will tell you what branch you are currently using
2. Type git branch <some name> to create a new branch
3. Type git switch <some name> to switch to this new name (redo step 1 to confirm this!)
○ Note: git checkout <some name> does the same thing but is the old way of doing it
4. Make some change to any file and git add <file name> and git commit <file name> that file
○ Note that these changes are only being committed to branch <some name>
5. Type git switch main
6. Type git merge <some name> (remember that main is the name of the other branch)
Hands On!
10 minutes
$ git branch demo
$ git checkout demo
$ change lines 10-24, add,
commit, log
$ git checkout master
$ make different changes on
lines 10-24, add, and
commit, log - notice how
our last commit isn’t there?
$ git merge demo
$ uh-oh
Merge conflict when Merging goes wrong
main
new branch
Lines
10-24
Lines
10-24
Merge Conflict Demo
main
branch2
...
Some arbitrary
number of prior
commits
git branch -c
branch2
Make an edit to
main.py, save,
add, commit
main
branch2
...
Some arbitrary
number of prior
commits
Modify LINE 9 of
file_actions.py,
save, add, commit
git branch -c
branch2
Make an edit to
main.py, save,
add, commit
main
branch2
...
Some arbitrary
number of prior
commits
git branch -c
branch2
Make an edit to
main.py, save,
add, commit
Modify LINE 9 of
file_actions.py,
save, add, commit
Modify LINE 9 of
file_actions.py,
save, add, commit
main
branch2
...
Some arbitrary
number of prior
commits
git branch -c
branch2
“updated
main.py”
git merge branch3
Modify LINE 9 of
file_actions.py,
save, add, commit
Modify LINE 9 of
file_actions.py,
save, add, commit
main
branch2
...
Some arbitrary
number of prior
commits
git branch -c
branch2
“updated
main.py”
git merge branch3
Modify LINE 9 of
file_actions.py,
save, add, commit
Modify LINE 9 of
file_actions.py,
save, add, commit
Successfully merged after
resolving all conflicts
main
branch2
...
Some arbitrary
number of prior
commits
“modified LINE 9
of file_actions.py”
git branch -c
branch2
“updated
main.py”
“modified LINE 9
of file_actions.py”
“resolved all conflicts
and merged”
Merge Conflict
5 minutes
$ open up the index.html file
and scroll to line 10
$ You should see some text
generated by git
$ Fix the conflict.
$ git add index.html
$ git commit -m “merged”
How does this all work with GitHub?
GitHub Repository Local Repository
GitHub Repository Local Repository
git pull
GitHub Repository Local Repository
git push
GitHub Repository Local Repository
git merge <branch name>
GitHub Repository
Local Repository
git push
What we talked
about today
1. Cloning/Forking
2. Staging & Committing
3. Branches
4. Merging
5. Pushing & Pulling
Other useful Git commands, concepts, and tools
● Rebasing:
https://www.youtube.com/watch?v=7Mh259hfxJg
● Making pull requests:
https://www.youtube.com/watch?v=8lGpZkjnkt4
● Git kraken: a GUI for Git
○ https://www.gitkraken.com/
Thank you all so much for coming!
Before you go...
● Would you like to join the GDSC team? We are hiring! Please apply here (deadline
Friday Sept 24th at midnight)
○ https://docs.google.com/forms/d/e/1FAIpQLSfsTcH9VLxIDb4r3Alv0wWT2s60lK
W-fAifeafe5E77BKJCQg/viewform
● What workshops would you like to see in the future? Please let us know here!
○ https://docs.google.com/forms/d/e/1FAIpQLScYpTz67WMiHqXYgH5uPobtSxry
oww7yCchmF9goagGFZxEzg/viewform
The “Intro to web development, HTML/CSS, and Javascript workshop!”
● October 2nd at 4 pm
● Milind will be leading that workshop!
We hope to see you next time at….

Git Init (Introduction to Git)

  • 1.
    $ git init Introto Git and GitHub Big thanks to Krish Chowdhary (GDSC Alumni) for allowing us to re-use some of his old slides!
  • 2.
    If you haven’talready installed it… (~8 min) Creating GitHub Account: github.com/join Download Git for... Windows: git-scm.com/download/win Linux: ● sudo apt install git-all (if you use a Debian-based Linux) ● OR sudo dnf install git-all (if you use a Red Hat-based Linux) MacOS: ● git-scm.com/download/mac ● OR type brew install git in your terminal (if you have homebrew)
  • 3.
    Some icebreaker questionsin the meantime 1. What year are you in? 2. What POSt are you in or planning on pursuing? 3. Have you ever used Git before? 4. What is your favourite programming language? 5. Any questions for us? 😄
  • 4.
  • 5.
  • 6.
    ● Git isa version control system ● A software that you interact with through your terminal/command line ● Allows you to keep track of changes made to your project ● Facilitates effective collaboration for multiple individuals working on one project
  • 7.
    Ever done somethinglike this? A better way? use Git
  • 8.
  • 9.
    ● A websitethat is the central location on the internet where you push (upload) and pull (download) code from ● From there people can view the project and its version history and starting contributing to it ● Think of it as a super advanced Google Drive ● Let’s take a look at an example GitHub repository: github.com/utmmcss/mcss-website-frontend ● Repository: the collection of all the versions of the files in a project ● What is GitHub?
  • 10.
    Git != GitHub Gitis a command line tool. GitHub is a website
  • 11.
  • 12.
  • 13.
    Hands-on activity: forkingand clon(e)ing (~5min) Your task: 1. Visit github.com/Daniel-Laufer/GDSCUTM-git-workshop 2. Click the “Fork” button ○ This will create a copy of this repository where your GitHub account is the owner 3. Then in your terminal (on your local computer) type: git clone <your forked repository url>.git ○ This will essentially download your repository from GitHub to your computer 4. Type: ls (first letter is a lowercase ‘L’). This command lists out everything in your current directory ○ You will see a new directory listed (aka a folder) 5. Type: cd <the name of this new directory> to “move” into that directory Don’t forget the .git suffix Remove the “<>” before using
  • 14.
  • 15.
    1. Staging &Committing
  • 16.
    1. Staging &Committing edit
  • 17.
    1. Staging &Committing edit save
  • 18.
    1. Staging &Committing “Main” git branch Initial commit
  • 19.
    1. Staging &Committing edit “Main” git branch Initial commit
  • 20.
    1. Staging &Committing edit save Initial commit “main” git branch
  • 21.
    1. Staging &Committing edit save add “main” git branch Initial commit
  • 22.
    1. Staging &Committing edit save commit add “main” git branch Initial commit New commit
  • 23.
    Hold up… what’sa commit again? It’s simply a change to your project that git records in its version history.
  • 24.
  • 25.
  • 26.
  • 27.
    1. Staging &Committing Initial Save New Save New Save New Save New Save
  • 28.
  • 29.
    Hands-on activity: adding& committing (~5 min) Instructions (ensure you are in the directory we downloaded last time) 1. Type git status ○ Git should tell you that everything is up to date 2. On your computer, make a change to any of the files and save that file 3. Now again type git status ○ You should see that git saw the change you just made 4. Type git add <your filename> ○ This will “stage” or in other words “prepare” your file for commiting 5. Type git commit -m “<whatever message you want goes here :)>” ○ This will tell git to “save” your file modifications in its version history 6. Type git log to see a list of your recent commits 7. (Optional) type git push to “push”, or in other words upload, your changes to your github
  • 30.
    Hands On! 10 minutes $cd into the repository $ Open index.html and make some changes $ git status $ git add index.html $ git commit -m “msg” $ git log
  • 31.
  • 32.
    Git branches ● Thinkof Git’s version history as a tree (the weird CS type of tree) ● Git branches are basically “independent lines/sections of development” c2 c1 c5 c3 c4 Branch #1 Branch #2
  • 33.
    Why use Branches? Example:a different branch used for different versions of a codebase c2 c1 c5 c3 c4 “main” branch “dev” branch
  • 34.
    Another example Using aseparate branch to develop a new feature. c2 c1 c5 c3 c4 “main” branch “create_cat_pic_api” branch
  • 35.
    How are branchesused? Continued Example: a different branch used for different versions of a codebase c2 c1 c5 c3 c4 “Production” branch “Development” branch
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
    Merging ● To “merge”your current branch with another you use the command git merge <other branch name> ● Git will intelligently combine all changes from that one branch with another ● foreshadowing: Git might have some trouble doing this sometimes :(
  • 42.
  • 43.
  • 44.
    Hands-on activity: Branchingand Merging Instructions (ensure you are in the directory we used last time) 1. Type git branch ○ This will tell you what branch you are currently using 2. Type git branch <some name> to create a new branch 3. Type git switch <some name> to switch to this new name (redo step 1 to confirm this!) ○ Note: git checkout <some name> does the same thing but is the old way of doing it 4. Make some change to any file and git add <file name> and git commit <file name> that file ○ Note that these changes are only being committed to branch <some name> 5. Type git switch main 6. Type git merge <some name> (remember that main is the name of the other branch)
  • 45.
    Hands On! 10 minutes $git branch demo $ git checkout demo $ change lines 10-24, add, commit, log $ git checkout master $ make different changes on lines 10-24, add, and commit, log - notice how our last commit isn’t there? $ git merge demo $ uh-oh
  • 46.
    Merge conflict whenMerging goes wrong main new branch Lines 10-24 Lines 10-24
  • 47.
  • 48.
    main branch2 ... Some arbitrary number ofprior commits git branch -c branch2 Make an edit to main.py, save, add, commit
  • 49.
    main branch2 ... Some arbitrary number ofprior commits Modify LINE 9 of file_actions.py, save, add, commit git branch -c branch2 Make an edit to main.py, save, add, commit
  • 50.
    main branch2 ... Some arbitrary number ofprior commits git branch -c branch2 Make an edit to main.py, save, add, commit Modify LINE 9 of file_actions.py, save, add, commit Modify LINE 9 of file_actions.py, save, add, commit
  • 51.
    main branch2 ... Some arbitrary number ofprior commits git branch -c branch2 “updated main.py” git merge branch3 Modify LINE 9 of file_actions.py, save, add, commit Modify LINE 9 of file_actions.py, save, add, commit
  • 52.
    main branch2 ... Some arbitrary number ofprior commits git branch -c branch2 “updated main.py” git merge branch3 Modify LINE 9 of file_actions.py, save, add, commit Modify LINE 9 of file_actions.py, save, add, commit Successfully merged after resolving all conflicts
  • 53.
    main branch2 ... Some arbitrary number ofprior commits “modified LINE 9 of file_actions.py” git branch -c branch2 “updated main.py” “modified LINE 9 of file_actions.py” “resolved all conflicts and merged”
  • 54.
    Merge Conflict 5 minutes $open up the index.html file and scroll to line 10 $ You should see some text generated by git $ Fix the conflict. $ git add index.html $ git commit -m “merged”
  • 55.
    How does thisall work with GitHub?
  • 56.
  • 57.
    GitHub Repository LocalRepository git pull
  • 58.
    GitHub Repository LocalRepository git push
  • 59.
    GitHub Repository LocalRepository git merge <branch name>
  • 60.
  • 61.
    What we talked abouttoday 1. Cloning/Forking 2. Staging & Committing 3. Branches 4. Merging 5. Pushing & Pulling
  • 62.
    Other useful Gitcommands, concepts, and tools ● Rebasing: https://www.youtube.com/watch?v=7Mh259hfxJg ● Making pull requests: https://www.youtube.com/watch?v=8lGpZkjnkt4 ● Git kraken: a GUI for Git ○ https://www.gitkraken.com/
  • 63.
    Thank you allso much for coming!
  • 64.
    Before you go... ●Would you like to join the GDSC team? We are hiring! Please apply here (deadline Friday Sept 24th at midnight) ○ https://docs.google.com/forms/d/e/1FAIpQLSfsTcH9VLxIDb4r3Alv0wWT2s60lK W-fAifeafe5E77BKJCQg/viewform ● What workshops would you like to see in the future? Please let us know here! ○ https://docs.google.com/forms/d/e/1FAIpQLScYpTz67WMiHqXYgH5uPobtSxry oww7yCchmF9goagGFZxEzg/viewform
  • 65.
    The “Intro toweb development, HTML/CSS, and Javascript workshop!” ● October 2nd at 4 pm ● Milind will be leading that workshop! We hope to see you next time at….