0% found this document useful (0 votes)
2 views

git-basics

Git is a version control system that helps manage changes to files and directories by tracking incremental changes through commits. It allows for organizing development workflows, collaborating with others, and protecting existing work. The document outlines basic Git commands, the lifecycle of files in Git, and best practices for using .gitignore to manage ignored files.

Uploaded by

varam10
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

git-basics

Git is a version control system that helps manage changes to files and directories by tracking incremental changes through commits. It allows for organizing development workflows, collaborating with others, and protecting existing work. The document outlines basic Git commands, the lifecycle of files in Git, and best practices for using .gitignore to manage ignored files.

Uploaded by

varam10
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Git Basics

relevant even to solo developers


• Protect existing work
Benefits of • Organize development workflow
Git
• Collaborate with other developers
First learn Git as a solo developer,
then add collaboration
Slides for each module will be attached to
the first lecture in the module
• Create a new directory
• Add some files
• Initialize Git repository
Exercise 1
• Add all files to the staging area
• Commit
• Read commit’s information in Git log
git status

git init

git add

Git git config --global user.name “…”

commands git config --global user.email “…”

git commit

git log
Commits
as Bank Transactions
Tx ID: <unique_id>
Date: <date_and_time>
Total: 1450
Description: Groceries
Amount: -50

Transactions Total: 1500


Tx ID: <unique_id>
Date: <date_and_time>
in bank Description: Salary

account Amount: +500

Tx ID: <unique_id>
Date: <date_and_time>

TIME
Total: 1000 Description: Initial deposit
Amount: +1000
Commit ID: <sha_id>
Date: <date_and_time>
Author: <author>
Repo state: f(sha_id) Description: <description>
Parent:

Commit ID: <sha_id>


Date: <date_and_time>
Git commits Repo state: f(sha_id)
Author: <author>
Description: Remove boilerplate
Parent:

Commit ID: <sha_id>


Date: <date_and_time>
Author: <author>
Repo state: f(sha_id)
Description: Initial template project

TIME
Parent: none
Git commits are incremental
state changes
diff --git a/count.txt b/count.txt
Before index ba70c99..a982fdc 100644 After
--- a/count.txt
Line 1 +++ b/count.txt Line 1
Line 2 Line 2
@@ -1,6 +1,8 @@
Line 3 Line 3
Line 1
Line 3 Line 4
Line 4 Line 2 Line 5
Line 8 Line 3 Line 6
Git diff -Line 3
Line 4
Line 7
Line 8
+Line 5
+Line 6
‘a’ or ‘-’ +Line 7 ‘b’ or ‘+’
Line 8
• Download the source code of JUnit4 unit-testing
framework to your machine
• Find the author, the date and the description of
commit 0bb3dfe29
Exercise 2
• How many files were affected by this commit
(hint: use --name-status flag)
• Review the code changes introduced by this
commit (no need to understand the code)
Lifecycle of a File in Git
Untracked Unmodified Modified Staged

add

commit

edit

stage

remove
One pattern per line

# … comment

fileOrDir ignore file or directory everywhere

Common dir/ ignore directory everywhere


.gitignore
patterns dir/fileOrDir ignore file or directory relative to .gitignore location

/dir/ ignore directory relative to .gitignore location

*.log ignore files with .log extension everywhere

**/dir/fileOrDir ignore file or directory everywhere, given specific parent


• Ignore build artifacts
.gitignore • Ignore files that may contain sensitive
best practices information (keys, usernames, passwords, etc.)
• Ignore user-specific configuration files
• Download the source code of Git Quiz
• List all files using ls -a and notice there is no
.gitignore file
• Find .gitignore template for Flutter projects on
the internet
Exercise 3
• Add .gitignore file to the source code
• Initialize Git repository inside that directory and
add the first commit
• Make sure Git doesn’t track ignored files (e.g. by
removing some of them)
Version Control System
• Git commits store the history of incremental
changes of repository’s state
• It is possible to reconstruct the state of the
repository from any Git commit (traversing its
ancestors)
Git commits • Each commit can be seen as a version of the
repository at a specific point in time
• You have control over commits in Git repository
(review, get back to, change, etc.)
In software engineering, version control (also
Version known as revision control, source control, or
Control source code management) is a class of systems
responsible for managing changes to computer
System programs, documents, large web sites, or other
collections of information.
Git is a Version Control System
Git Basics
Summary
• Git is a version control system
• Directories become Git repositories once Git
initializes hidden .git directory inside them
• Git commits store information about incremental
Git basics changes of repository’s state
• Git tracks changes to individual files
• Lifecycle of tracked files inside Git repository:
unmodified -> modified -> staged ->
unmodified

You might also like