SlideShare a Scribd company logo
1 of 30
Download to read offline
Git 101 
for everyone 
@sengopal
Who is this for? 
● Folks starting to use Git or foraying just now 
● Folks who are using SmartGit :) 
● Using Git as CVCS 
http://rogerdudler.github.io/git-guide/
Clearcase Vs. Git 
Central Vs. Distributed
Git How
Why command line 
No Installation 
Simple to use 
Comes bundled with Git as Git-Bash 
Consistent across OS
A simple workflow 
Clone or create new repository 
Update/Add files 
Stage the changes 
Review the changes 
Commit the changes
Git Setup 
$ git config --global user.name "John Doe" 
$ git config --global user.email johndoe@example.com 
$ git config --global color.ui true
Nomenclature
Create a new Repository 
$ cd project/ 
$ git init # initializes the repository 
$ git add . # add those 'unknown' files - ADDS FOR STAGE 
$ git commit # commit all changes, edit changelog entry 
- M 
$ git rm --cached <file>... # ridiculously complicated 
command to undo, in case you forgot .gitignore 
$ git reset HEAD <file> # same as before 
$ git init project002 #shortcut for mkdir project002 && 
cd project002 && git init
Git Clone 
$ git clone git://github.com/sengopal/simplegit.git 
Initialized empty Git repository in 
/private/tmp/simplegit/.git/ 
remote: Counting objects: 100, done. 
remote: Compressing objects: 100% (86/86), done. 
remote: Total 100 (delta 35), reused 0 (delta 0) 
Receiving objects: 100% (100/100), 9.51 KiB, done. 
Resolving deltas: 100% (35/35), done. 
$ cd simplegit/ 
$ ls 
copy the entire history of that project so you have it locally
Git status 
$ git status 
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
# new file: README 
# new file: hello.py 
# 
# Changed but not updated: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in 
working directory) 
# 
# modified: README 
#
Git add 
Start tracking new files and also to stage changes to already tracked files 
$ touch README.md; echo “test” > README.md 
$ git status 
$ git add . 
$ git status 
$ git diff 
Shortcut: git commit -a # the -a flag pulls in all modified files 
will commit all changed files (but not new files, those need to be added to the 
index with git-add). If you want to commit only certain files then you will need to 
stage them first with git-add
Git diff 
To compare two revisions of a file, or your current file and a previous revision 
$ git diff README.md 
$ git diff --staged README.md 
$ git diff HEAD README.md 
$ git diff --stat README.md 
To compare 2 revisions of a file: 
$ git diff <commit1> <commit2> <file_name>
.gitignore 
$ git add .gitignore 
will use its rules when looking at files to commit to ignore from staging 
$ git rm --cached filename 
will not ignore a file that was already tracked before a rule was added to this file 
# to remove the tracked file - Caution: This deletes the file 
$ git config --global core.excludesfile ~/. 
gitignore_global 
file can be committed into the repository, thus sharing the rule list with any 
other users that clone the repository.
Git Commit 
$ git commit -m 'my awesome changes' 
-m option not given - open a text editor for you to write your commit message. 
$ git commit -a 
automatically stage all tracked, modified files before the commit
Git push 
remote branches 
are identical to local branches except that Git will not allow you to check them 
out. However, you can merge from them, diff them to other branches, run 
history logs on them, etc. You do all of that stuff locally after you synchronize. 
$ git push <remote> <branch> 
# push new commits to the <branch> on the <remote> repository 
For someone coming from CVS, the commit to the central 
repository now requires two steps. 
$ git clone 
# creates a remote called origin for push and fetch
Git pull and fetch 
$ git pull <remote> <branch> 
# fetches code and merges it 
$ git fetch <remote> <branch> 
# fetches code without merging 
$ git pull --tag <remote> <branch> 
# pulls tags as well
Git reset 
just a plain old git reset should unstage accidental git add 
$ git reset --soft 
undo the last commit and put the files back onto the stage 
$ git reset --hard 
undo the last commit, unstage files AND undo any changes in the working dir 
$ git-reset --hard <hash> 
Revert to a previous commit by hash 
$ git-reset --hard HEAD^ 
your last commit before pull/merge
Git reset 
$ git reset HEAD <file> 
unstage file and copy from latest commit 
$ git reset -- <file> 
unstages specific files and copy files from the stage 
$ git checkout HEAD -- files 
copies files from the latest commit to both the stage and the working directory. 
$ git checkout -- files 
copies files from the stage to the working directory. Use this to throw away local 
changes.
git branch 
The default branch in a git repository is called master. 
$ git branch <branch-name> 
To create a new branch use 
$ git branch 
To see a list of all branches in the current repository type 
$ git checkout <branch-name> 
If you want to switch to another branch you can use 
$ git checkout -b <branch-name> 
To create a new branch and switch to it in one step 
$ git branch -d <branch-name> # To delete a branch 
$ git stash branch <branch-name> # To create a branch with current 
changes
git rebase 
$ git checkout experiment 
$ git rebase master 
First, rewinding head to replay your work on top of it... 
Applying: added staged command 
$ git rebase -i 
$ git rebase --interactive
git merge 
If you want to merge a branch (e.g. master to release), make sure your current 
branch is the target branch you'd like to merge into (use git branch or git status to 
see your current branch). 
$ git merge experiment 
where experiment is the name of the branch you want to merge with the current 
branch 
$ git diff 
to see pending conflicts you have to resolve. 
$ git checkout -b linux-work # create a new branch 
$ <make changes> 
$ git commit -a 
$ git checkout master # go back to master branch 
$ git merge linux-work # merge changesets from linux-work
git merge 
$ git checkout master 
$ git rebase topic 
First, rewinding head to replay your work on top of it... 
Fast-forwarded master to topic. 
This command lays the latest changes to topic right on top of the master 
branch, and preserves all of your commit history- laying them right on the end 
of the master branch’s commit history. 
$ git merge --squash topic 
This command will result in a commit log like a normal merge- meaning that all 
of the individual commit messages from the topic branch will become one 
single “merge” message.
mergetool 
$ cat /usr/local/bin/extMerge 
#!/bin/sh 
/Applications/p4merge.app/Contents/MacOS/p4merge $* 
$ git config --global merge.tool extMerge 
$ git config --global mergetool.extMerge.cmd 'extMerge 
"$BASE" "$LOCAL" "$REMOTE" "$MERGED"' 
$ git config --global mergetool.trustExitCode = false 
~/.gitconfig 
[merge] 
tool = extMerge 
[mergetool "extMerge"] 
cmd = extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" 
trustExitCode = false
gitconfig 
$ git config --global core.editor emacs 
$ git config --global core.pager '' 
$ git config --global color.ui true 
$ git config --global diff.external extDiff 
$ git config --global core.whitespace  
trailing-space,space-before-tab,indent-with-non-tab 
$ git config --global merge.stat true
Branching
git remote 
$ git remote add origin user@server:/path/to/project.git 
adding a remote branch 
$ git remote -v 
origin git@github.com:github/git-reference.git (fetch) 
origin git@github.com:github/git-reference.git (push) 
list the remotes available 
$ git remote rm origin 
removing an existing remote alias
Quick tips 
$ git log -- filename 
see the history of revisions to a file 
$ gitk 
inspect history visually, shows you how the revisions are connected 
$ git log 
this pipes a log of the current branch into your PAGER 
$ git log -p 
# same as above, but append a patch after each commit message 
$ git show HEAD 
show commit info, diffstat and patch of the tip of current branch
Quick tips 
$ git filter-branch --tree-filter 'rm -f filename' HEAD 
remove all instances of a file from every commit 
$ git filter-branch --env-filter  
"export GIT_AUTHOR_EMAIL=you@email.com" HEAD 
change your email in all commits 
$ git blame <file-name> 
history of user changes in a file 
$ git log --pretty=oneline --graph 
pretty log with a graph of changes done
Future References 
http://gitimmersion.com 
http://git-scm.com/doc 
http://help.github.com

More Related Content

What's hot

Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewRueful Robin
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 

What's hot (20)

Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
git and github
git and githubgit and github
git and github
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git training v10
Git training v10Git training v10
Git training v10
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git basic
Git basicGit basic
Git basic
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 

Similar to Git and github 101 (20)

Git
GitGit
Git
 
Git
GitGit
Git
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615
 
Git
GitGit
Git
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git and github
Git and githubGit and github
Git and github
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git Concepts, Commands and Connectivity
Git Concepts, Commands and ConnectivityGit Concepts, Commands and Connectivity
Git Concepts, Commands and Connectivity
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Git github
Git githubGit github
Git github
 
Git
GitGit
Git
 
Git_real_slides
Git_real_slidesGit_real_slides
Git_real_slides
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
 
GitSetupLinux
GitSetupLinuxGitSetupLinux
GitSetupLinux
 

More from Senthilkumar Gopal

Portfolio for CS 6475 Computational Photography
Portfolio for CS 6475 Computational PhotographyPortfolio for CS 6475 Computational Photography
Portfolio for CS 6475 Computational PhotographySenthilkumar Gopal
 
IBM Index Conference - 10 steps to build token based API Security
IBM Index Conference - 10 steps to build token based API SecurityIBM Index Conference - 10 steps to build token based API Security
IBM Index Conference - 10 steps to build token based API SecuritySenthilkumar Gopal
 
How developers write documentation
How developers write documentationHow developers write documentation
How developers write documentationSenthilkumar Gopal
 
Application resiliency using netflix hystrix
Application resiliency using netflix hystrixApplication resiliency using netflix hystrix
Application resiliency using netflix hystrixSenthilkumar Gopal
 

More from Senthilkumar Gopal (6)

Portfolio for CS 6475 Computational Photography
Portfolio for CS 6475 Computational PhotographyPortfolio for CS 6475 Computational Photography
Portfolio for CS 6475 Computational Photography
 
IBM Index Conference - 10 steps to build token based API Security
IBM Index Conference - 10 steps to build token based API SecurityIBM Index Conference - 10 steps to build token based API Security
IBM Index Conference - 10 steps to build token based API Security
 
How developers write documentation
How developers write documentationHow developers write documentation
How developers write documentation
 
Bdd using Cucumber
Bdd using CucumberBdd using Cucumber
Bdd using Cucumber
 
Application resiliency using netflix hystrix
Application resiliency using netflix hystrixApplication resiliency using netflix hystrix
Application resiliency using netflix hystrix
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 

Recently uploaded

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Recently uploaded (20)

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

Git and github 101

  • 1. Git 101 for everyone @sengopal
  • 2. Who is this for? ● Folks starting to use Git or foraying just now ● Folks who are using SmartGit :) ● Using Git as CVCS http://rogerdudler.github.io/git-guide/
  • 3. Clearcase Vs. Git Central Vs. Distributed
  • 5. Why command line No Installation Simple to use Comes bundled with Git as Git-Bash Consistent across OS
  • 6. A simple workflow Clone or create new repository Update/Add files Stage the changes Review the changes Commit the changes
  • 7. Git Setup $ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com $ git config --global color.ui true
  • 9. Create a new Repository $ cd project/ $ git init # initializes the repository $ git add . # add those 'unknown' files - ADDS FOR STAGE $ git commit # commit all changes, edit changelog entry - M $ git rm --cached <file>... # ridiculously complicated command to undo, in case you forgot .gitignore $ git reset HEAD <file> # same as before $ git init project002 #shortcut for mkdir project002 && cd project002 && git init
  • 10. Git Clone $ git clone git://github.com/sengopal/simplegit.git Initialized empty Git repository in /private/tmp/simplegit/.git/ remote: Counting objects: 100, done. remote: Compressing objects: 100% (86/86), done. remote: Total 100 (delta 35), reused 0 (delta 0) Receiving objects: 100% (100/100), 9.51 KiB, done. Resolving deltas: 100% (35/35), done. $ cd simplegit/ $ ls copy the entire history of that project so you have it locally
  • 11. Git status $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README # new file: hello.py # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README #
  • 12. Git add Start tracking new files and also to stage changes to already tracked files $ touch README.md; echo “test” > README.md $ git status $ git add . $ git status $ git diff Shortcut: git commit -a # the -a flag pulls in all modified files will commit all changed files (but not new files, those need to be added to the index with git-add). If you want to commit only certain files then you will need to stage them first with git-add
  • 13. Git diff To compare two revisions of a file, or your current file and a previous revision $ git diff README.md $ git diff --staged README.md $ git diff HEAD README.md $ git diff --stat README.md To compare 2 revisions of a file: $ git diff <commit1> <commit2> <file_name>
  • 14. .gitignore $ git add .gitignore will use its rules when looking at files to commit to ignore from staging $ git rm --cached filename will not ignore a file that was already tracked before a rule was added to this file # to remove the tracked file - Caution: This deletes the file $ git config --global core.excludesfile ~/. gitignore_global file can be committed into the repository, thus sharing the rule list with any other users that clone the repository.
  • 15. Git Commit $ git commit -m 'my awesome changes' -m option not given - open a text editor for you to write your commit message. $ git commit -a automatically stage all tracked, modified files before the commit
  • 16. Git push remote branches are identical to local branches except that Git will not allow you to check them out. However, you can merge from them, diff them to other branches, run history logs on them, etc. You do all of that stuff locally after you synchronize. $ git push <remote> <branch> # push new commits to the <branch> on the <remote> repository For someone coming from CVS, the commit to the central repository now requires two steps. $ git clone # creates a remote called origin for push and fetch
  • 17. Git pull and fetch $ git pull <remote> <branch> # fetches code and merges it $ git fetch <remote> <branch> # fetches code without merging $ git pull --tag <remote> <branch> # pulls tags as well
  • 18. Git reset just a plain old git reset should unstage accidental git add $ git reset --soft undo the last commit and put the files back onto the stage $ git reset --hard undo the last commit, unstage files AND undo any changes in the working dir $ git-reset --hard <hash> Revert to a previous commit by hash $ git-reset --hard HEAD^ your last commit before pull/merge
  • 19. Git reset $ git reset HEAD <file> unstage file and copy from latest commit $ git reset -- <file> unstages specific files and copy files from the stage $ git checkout HEAD -- files copies files from the latest commit to both the stage and the working directory. $ git checkout -- files copies files from the stage to the working directory. Use this to throw away local changes.
  • 20. git branch The default branch in a git repository is called master. $ git branch <branch-name> To create a new branch use $ git branch To see a list of all branches in the current repository type $ git checkout <branch-name> If you want to switch to another branch you can use $ git checkout -b <branch-name> To create a new branch and switch to it in one step $ git branch -d <branch-name> # To delete a branch $ git stash branch <branch-name> # To create a branch with current changes
  • 21. git rebase $ git checkout experiment $ git rebase master First, rewinding head to replay your work on top of it... Applying: added staged command $ git rebase -i $ git rebase --interactive
  • 22. git merge If you want to merge a branch (e.g. master to release), make sure your current branch is the target branch you'd like to merge into (use git branch or git status to see your current branch). $ git merge experiment where experiment is the name of the branch you want to merge with the current branch $ git diff to see pending conflicts you have to resolve. $ git checkout -b linux-work # create a new branch $ <make changes> $ git commit -a $ git checkout master # go back to master branch $ git merge linux-work # merge changesets from linux-work
  • 23. git merge $ git checkout master $ git rebase topic First, rewinding head to replay your work on top of it... Fast-forwarded master to topic. This command lays the latest changes to topic right on top of the master branch, and preserves all of your commit history- laying them right on the end of the master branch’s commit history. $ git merge --squash topic This command will result in a commit log like a normal merge- meaning that all of the individual commit messages from the topic branch will become one single “merge” message.
  • 24. mergetool $ cat /usr/local/bin/extMerge #!/bin/sh /Applications/p4merge.app/Contents/MacOS/p4merge $* $ git config --global merge.tool extMerge $ git config --global mergetool.extMerge.cmd 'extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"' $ git config --global mergetool.trustExitCode = false ~/.gitconfig [merge] tool = extMerge [mergetool "extMerge"] cmd = extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" trustExitCode = false
  • 25. gitconfig $ git config --global core.editor emacs $ git config --global core.pager '' $ git config --global color.ui true $ git config --global diff.external extDiff $ git config --global core.whitespace trailing-space,space-before-tab,indent-with-non-tab $ git config --global merge.stat true
  • 27. git remote $ git remote add origin user@server:/path/to/project.git adding a remote branch $ git remote -v origin git@github.com:github/git-reference.git (fetch) origin git@github.com:github/git-reference.git (push) list the remotes available $ git remote rm origin removing an existing remote alias
  • 28. Quick tips $ git log -- filename see the history of revisions to a file $ gitk inspect history visually, shows you how the revisions are connected $ git log this pipes a log of the current branch into your PAGER $ git log -p # same as above, but append a patch after each commit message $ git show HEAD show commit info, diffstat and patch of the tip of current branch
  • 29. Quick tips $ git filter-branch --tree-filter 'rm -f filename' HEAD remove all instances of a file from every commit $ git filter-branch --env-filter "export GIT_AUTHOR_EMAIL=you@email.com" HEAD change your email in all commits $ git blame <file-name> history of user changes in a file $ git log --pretty=oneline --graph pretty log with a graph of changes done
  • 30. Future References http://gitimmersion.com http://git-scm.com/doc http://help.github.com