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

u01 Java Maven Git

Uploaded by

jessicafan3ck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

u01 Java Maven Git

Uploaded by

jessicafan3ck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Java Workflow, Maven, Git

Prof Prairie
UNC COMP 301
Fall 24
Announcements
• Gradescope code added to Canvas
• Midterm1 date is Wed, October 2nd
• My Digital Hand won’t let me register the course, so we are going to
try csxl.unc.edu, to be setup by Monday.
• My office hours are moving to Thursdays (starting Aug 29th) 1:30-4.

• Questions?
Q: What happens when you press
the “run” button in your IDE?
Q: What happens when you press
the “run” button in your IDE?

Is this how your users


will run the program?

(probably not…)
Introduction
Packaging application code into a final, distributable product is a
crucial part of software development
 Code is only useful if it is being used
 Programming languages have different approaches to packaging and
distributing code

Let’s learn about Java’s build process


Running Java code is a two-step process
1. Compile the source code into bytecode
2. Execute the resulting bytecode
Compiling and executing Java code
How to use the Java code you write
To Compile or Not To Compile
• Interpreted languages
 Python, JavaScript
 Program source code parsed and interpreted for execution by language interpreter
 Advantage: same source code runs on different platforms and processors
 Disadvantage: slower

• Compiled languages
 C, C++, Rust
 Compiler parses and translates source code into machine executable code
• Must be done for the specific instruction set architecture (ISA) used by the processor
 Advantage: runs fast, can be highly optimized
 Disadvantage: need to create a machine specific version for every kind of machine.
Java's Big Idea
• Best of both worlds.
• Compile source code to the "machine code" of a virtual machine
 Java Virtual Machine (JVM)

• Provide machine specific implementations of the virtual machine


• Advantage: write once, run everywhere.
• Disadvantage: some performance
Compiling a Java program
Compile – The process of translating a program from source code into a language that a
machine can more easily understand

HelloWorld.java (source code) HelloWorld.class (bytecode)


package com.comp301.lec01.ex01; CA FE BA BE 00 00 00 33 00 22 0A 00 02 00
Java Development 03 00 04 0C 00 05 00 06 01 00 10 6A 61 76
public class HelloWorld { 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 01
public static void main(String[] args) {
Kit (JDK) 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56
System.out.println("Hello, world!"); 09 00 08 00 09 07 00 0C 00 0B 00 0C 01 00
} 10 6A 61 76 61 2F 6C 61 2F 53 79 74 65 6D
} 01 00 03 6F 75 74 01 00 15 4C 66 A0 65 63

The JDK includes a Java


Files ending in .java Files ending in .class
compiler to convert Java
contain ASCII Java source code contain binary bytecode
source code to bytecode
Executing a Java program
Execute – The process of feeding a compiled program into a machine that can follow
the instructions
Execute
HelloWorld.java (source code) HelloWorld.class (bytecode)
package com.comp301.lec01.ex01; CA FE BA BE 00 00 00 33 00 22 0A 00 02 00
Java Development 03 00 04 0C 00 05 00 06 01 00 10 6A 61 76
public class HelloWorld { 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 01
public static void main(String[] args) {
Kit (JDK) 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56
System.out.println("Hello, world!"); 09 00 08 00 09 07 00 0C 00 0B 00 0C 01 00
} 10 6A 61 76 61 2F 6C 61 2F 53 79 74 65 6D
} 01 00 03 6F 75 74 01 00 15 4C 66 A0 65 63

Compiled bytecode can Java Virtual Machine


be executed by a JVM (JVM)
Compiling and executing
large Java projects
Compiling and executing large projects
Large projects commonly have:
1. Hundreds of .java source files to compile
2. External dependencies that must be imported

Dependency – A “third-party” library


containing code that you didn’t write
yourself, but is used in your project

In COMP 301, we will use two


third-party dependencies:
JUnit and JavaFX
Dependencies and all source
Compiling a large project code files must be passed to
the JDK for compilation

Source Code Bytecode


(code you wrote) (compiled machine instructions)

HelloWorldA.java
Java Development
HelloWorldA.class
package com.comp301.lec01.ex01; Kit (JDK) CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
HelloWorldB.java
public class HelloWorld { HelloWorldB.class
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
public static void main(String[] args)
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
{ package com.comp301.lec01.ex01; CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
HelloWorldC.java
System.out.println("Hello, world!");
} public class HelloWorld {
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
HelloWorldC.class
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
79 74 65 6D 01 00 03 6F 75 74 01
} public static void main(String[] args) 74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
{ package com.comp301.lec01.ex01; 00 15 4C 66 A0 65 63
8 29CA56FE09BA00BE080000000900073300000C22000A0B000002 0
HelloWorldD.java
System.out.println("Hello, world!");
}public class HelloWorld {
0C 01 000010046A0C6100760561002F066C0161002F10536A 61
0 03
HelloWorldD.class
79 747665616D2F016C0061036E6F67752F744F0162 6A 65 63
} public static void main(String[] args) 74 4C
01 66
00 A0
06 65
3C 63
69 6E 69 74 3E 01 00 03 2
{ package com.comp301.lec01.ex01; 00 15
8 29CA56FE 09
BA00BE080000000900073300000C22 00
0A0B0000
02 0
System.out.println("Hello, world!"); 0C00103 00
00 10
04 6A
0C 61
00 76
05 61
00 2F
06 6C
01 61
00 2F
10 53
6A 61

}
}public class HelloWorld {

{
public static void main(String[] args) Dependencies 79 74
00 74
76 65
15 01
61 6D
4C 00
2F 01
66 06
6C 00
A0 3C
61 03
65 69
6E 6F
67 75
2F 74
4F 01
62 6A 65 63
63 6E 69 74 3E 01 00 03 2

(code you didn’t write)


8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
System.out.println("Hello, world!"); 0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
} 79 74 65 6D 01 00 03 6F 75 74 01
} 00 15 4C 66 A0 65 63

JUnit.jar
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
Multiple source code files JavaFX.jar
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
CA56
8 29 FE 09
BA00BE08 000000090007
3300000C22 00
0A0B000002 0
0C00103 00
00 10
04 6A
0C 61
00 76
05 61
00 2F
06 6C
01 61
00 2F
10 53
6A 61
76 65
79 74 61 6D
2F 016C 00
61 03
6E 6F
67 75
2F 74
4F 01
62 6A 65 63
00 74
15 01
4C 00
66 06A0 3C
65 69
63 6E 69 74 3E 01 00 03 2
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
Dependencies are usually 0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
79 74 65 6D 01 00 03 6F 75 74 01

in .jar file format


00 15 4C 66 A0 65 63
Dependencies and compiled
Executing a large project bytecode must be passed to
the JVM for execution
Bytecode
(compiled machine instructions)

HelloWorldA.class
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0

HelloWorldB.class
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61 Java Virtual Machine
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
(JVM)
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
HelloWorldC.class
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
79 74 65 6D 01 00 03 6F 75 74 01
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
00 15 4C 66 A0 65 63
8 29CA56FE09BA00BE080000000900073300000C22000A0B000002 0
0C 00103000010046A0C6100760561002F066C0161002F10536A 61
HelloWorldD.class
79 747665616D2F016C0061036E6F67752F744F0162 6A 65 63
74 4C
00 15 01 66
00 A0
06 65
3C 63
69 6E 69 74 3E 01 00 03 2
8 29CA56FE 09
BA00BE080000000900073300000C22 00
0A0B000002 0
0 03 00 04
0C 01 00 10 6A 61 0C 00 76
05 61
00 2F
06 6C
01 61
00 2F
10 53
6A 61
79 7476 65
61 6D
2F 01
6C 00
61 03
6E 6F
67 75
2F 74
4F 01
62 6A 65 63
00 74
15 01
4C 00
66 06
A0 3C
65 69
63 6E 69 74 3E 01 00 03 2
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
Dependencies
79 74 65 6D 01 00 03 6F 75 74 01
00 15 4C 66 A0 65 63 (code you didn’t write)

JUnit.jar
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
JavaFX.jar
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
CA56
8 29 FE 09
BA00BE08 000000090007
3300000C22 00
0A0B000002 0
0C00103 00
00 10
04 6A
0C 61
00 76
05 61
00 2F
06 6C
01 61
00 2F
10 53
6A 61
76 65
79 74 61 6D
2F 016C 00
61 03
6E 6F
67 75
2F 74
4F 01
62 6A 65 63
00 74
15 01
4C 00
66 06A0 3C
65 69
63 6E 69 74 3E 01 00 03 2
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
79 74 65 6D 01 00 03 6F 75 74 01
00 15 4C 66 A0 65 63
Packaging a compiled Java program
Packaging a Java program A “jar” file contains the bytecode and
other assets necessary to execute the
project in a distributable format
Packaged program
Bytecode (jar file)
(compiled machine instructions)

HelloWorldA.class
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0 Java Virtual Machine
HelloWorldB.class
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 HelloWorld.jar (JVM)
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61 (JAR file)
HelloWorldC.class
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
79 74 65 6D 01 00 03 6F 75 74 01
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
00 15 4C 66 A0 65 63
8 29CA56FE09BA00BE080000000900073300000C22000A0B000002 0
0C 00103000010046A0C6100760561002F066C0161002F10536A 61
HelloWorldD.class
79 747665616D2F016C0061036E6F67752F744F0162 6A 65 63
74 4C
01 66
00 A0
06 65
3C 63
69 6E 69 74 3E 01 00 03 2
JAR files can be
00 15
8 29CA56FE 09
BA00BE080000000900073300000C22 00
0A0B000002 0
0 03 00 04
0C 01 00 10 6A 61 0C 00 76
05 61
00 2F
06 6C
01 61
00 2F
10 53
6A 61
76 65
61 6D
2F 01
6C 00
61 03
6E 6F
67 75
2F 74
4F 01
62 6A 65 63
executed directly
79 74
00 74
15 01
4C 00
66 06
A0 3C
65 69
63 6E 69 74 3E 01 00 03 2
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
Dependencies
79 74 65 6D 01 00 03 6F 75 74 01
00 15 4C 66 A0 65 63 (code you didn’t write)

JUnit.jar
CA FE BA BE 00 00 00 33 00 22 0A 00 02 0
0 03 00 04 0C 00 05 00 06 01 00 10 6A 61
JavaFX.jar
76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63
74 01 00 06 3C 69 6E 69 74 3E 01 00 03 2
CA56
8 29 FE 09
BA00BE08 000000090007
3300000C22 00
0A0B000002 0
0C00103 00
00 10
04 6A
0C 61
00 76
05 61
00 2F
06 6C
01 61
00 2F
10 53
6A 61
76 65
79 74 61 6D
2F 016C 00
61 03
6E 6F
67 75
2F 74
4F 01
62 6A 65 63
00 74
15 01
4C 00
66 06A0 3C
65 69
63 6E 69 74 3E 01 00 03 2
8 29 56 09 00 08 00 09 07 00 0C 00 0B 00
0C 01 00 10 6A 61 76 61 2F 6C 61 2F 53
79 74 65 6D 01 00 03 6F 75 74 01
00 15 4C 66 A0 65 63
When poll is active respond at
PollEv.com​/profprairie
Let’s look at the .class file!
Decompilers can get almost an exact copy of the
source code.
Compiling and executing Java
from the command line
Compiling from the command line
Terminal

$ javac -classpath C:\proj\deps;C:\proj\junit.jar HelloWorldA.java HelloWorldB.java

“compile a Java program” List dependencies List .java source files


to include during compiling to compile into .class files

Separate multiple dependencies Separate multiple source


with semicolons files with spaces

Dependencies may be .jar files, Source files must have


.zip files, or paths to directories .java extension
containing .class or .java files
Executing from the command line
Terminal

$ java -classpath C:\proj\deps;C:\proj\junit.jar com.comp301.lec01.ex01.HelloWorld arg01

“execute a Java program” List of bytecode files Full name of the class Command line
to include during execution to be executed arguments

Separate multiple bytecode The specified class must


locations with semicolons define a main() function

Bytecode locations may be .jar


files, .zip files, or paths to
directories containing .class files
Java packages and imports
This is not the same as “packaging” your code in a .jar file!
https://docs.oracle.com/javase/8/docs/api/
Java packages HelloWorld.java (source code)
package com.comp301.lec01.ex01;

What does this line mean? public class HelloWorld {


public static void main(String[] args) {
// TODO
It declares which package the class }
}

HelloWorld lives in

“A package is a namespace that organizes a set of


related classes and interfaces. Conceptually you can
think of packages as being similar to different
folders on your computer.” – Oracle

https://docs.oracle.com/javase/tutorial/java/concepts/package.html
HelloWorld.java (source code)

Java packages package com.comp301.lec01.ex01;

public class HelloWorld {


public static void main(String[] args) {
// TODO
Packages are for organizing class files into }
}

different “units”
 Put related class files in the same package
 Put unrelated class files in different
packages

Don’t be afraid to make new packages


 You are in control of your project’s
organizational scheme

Package names imply hierarchy


 Use the "." character
Packages on disk HelloWorld.java (source code)
package com.comp301.lec01.ex01;

public class HelloWorld {


public static void main(String[] args) {
// TODO

Packages are associated with a }


}

particular folder path on disk


 Each package name part is a Based on this rule, what’s
subfolder the path of HelloWorld.java?

 Class files are placed in the bottom


most folder associated with their com/comp301/lec01/ex01/HelloWorld.java
package name
 To import everything in that
subdirectory, use a star character(*).
Project folder structure

Root folder is blue


(in IntelliJ)

Subfolders implied by
package name
Which of the following is true:

I. HelloWorld and HelloWorld2 are both in the


package called com.comp301.lec01

II. HelloWorld and HelloWorld2 are in different


packages that must be referred to as ex01 and
ex02

III. It is possible to import both at the same


time by saying com.comp301.*
Relation to folders HelloWorld.java (source code)
package com.comp301.lec01.ex01;
Packages correspond import com.comp301.lec01.ex02.HelloWorld2;
But, they share to a folder path
common prefix public class HelloWorld {
public static void main(String[] args) {
folder path
HelloWorld2.sayHello();
}
}

HelloWorld2.java (source code)


package com.comp301.lec01.ex02;

public class HelloWorld2 {


public static void sayHello() {
Different packages, System.out.println("Hello, world!");
}
different folders }
Referencing across packages
HelloWorld.java (source code)
HelloWorld has a package com.comp301.lec01.ex01;
main() method
public class HelloWorld {
public static void main(String[] args) {
com.comp301.lec01.ex02.HelloWorld2.sayHello();
HelloWorld.main() calls }
}
HelloWorld2.sayHello()

HelloWorld2.java (source code)


package com.comp301.lec01.ex02;

public class HelloWorld2 {


public static void sayHello() {
System.out.println("Hello, world!");
}
}
Importing across packages HelloWorld.java (source code)
package com.comp301.lec01.ex01;
Import statement reduces
verbosity of referring to import com.comp301.lec01.ex02.HelloWorld2;
names in other packages
public class HelloWorld {
public static void main(String[] args) {
HelloWorld2.sayHello();
}
}

HelloWorld2.java (source code)


package com.comp301.lec01.ex02;

public class HelloWorld2 {


public static void sayHello() {
System.out.println("Hello, world!");
}
}
Java build process
What is the “build process”?

In software engineering, the “build process” is the act of converting a


project’s source material into a shippable software product

Source material refers to any


Shippable means the output is
resources stored in the project’s
packaged up and ready to be
GitHub repository, such as source
sent to the customer
code, image files, raw data, etc.
Java’s build process
Build process tasks vary from project to project
and from language to language

Here are common build process tasks for Java projects:


1. clean Delete any leftover temporary files from the project folder
2. compile Compile the project source code into bytecode
3. test Run the unit tests for the project
4. package Pack the compiled code into a distributable format
5. verify Check that the packaged output meets quality criteria
6. site Generate documentation for the produced code
7. deploy Send the packaged output to customers
Build automation tools

Java JavaScript C/C++ Ruby


Ant Grunt
Gradle make Rake
Maven Gulp
Maven
Build automation tool for Java
Maven terminology

pom.xml Main project configuration file

Dependency An external module or library that your project uses

Archetype A template for creating new Maven projects

Artifact The packaged output file(s) produced by the project

Lifecycle A configurable build process task


Source code
(.java files)

Test code
(.java files)

Compiled output
(.class files)

All COMP 301


programming assignments
will follow this structure

Configuration file
Dependencies
This is an example Maven
configuration file (pom.xml)
 Written in XML
 Typically placed in the
root of the project folder
 Specifies various settings
for the project
Project version and artifact information

Project name

Java version and other properties

Dependencies

Lifecycle configuration
Many public Java libraries provide a
Maven dependency snippet that you
can copy and paste into your
pom.xml configuration file
JavaFX has been added to pom.xml

Maven will automatically download


the correct .jar file and link it
during compilation/execution
Maven config uses
“convention over
configuration”

That means most settings


are optional and have
reasonable default values
Pressing this button in IntelliJ opens
a drawer where you can execute
Maven lifecycles (aka build tasks)
The Git version control system
An introduction to version control
What is the difference between git, github,
and gitlab?
• Git is the open-source tool for tracking changes to a code base.
Freely available and easy to install.
 It must save the information somewhere.

• Github (owned my Microsoft) runs git in the cloud and provides


storage through free and paid plans.

• GitLab (self owned) also runs git in the cloud and has a different
pricing structure, more geared towards private industry usage
rather than open-opensource
Introduction
Version control is the practice of tracking changes made to a codebase
• Periodically capture a “snapshot” of the code
• Archive all snapshots taken in case you need to refer back to them
• Why is this a good idea?
• All software companies have a version control system in place

Git is by far the most well-known


Well-known version control systems
version control system, and is the
• Git one we will use in COMP 301
• CVS
• Apache Subversion (SVN)
• Mercurial
What is a “commit”?
When a commit is created, it is given a unique identifier
generated based on the content of the files stored inside Every commit has a parent
commit, forming a graph
This unique identifier can be used to reference the commit

Commit Commit Commit


f22c9a3 ac901f8 d0a7bc1

folder folder folder

folder folder folder


file file file
file file file
file file

• Make some changes • Make some more changes


• Create a new commit • Commit those changes, too
What is a “repository”?
Usually, a remote repository is stored on GitHub,
and a local repository is stored on your computer

Repository
Commit Commit Commit
f22c9a3 ac901f8 d0a7bc1

folder folder folder

folder folder folder


file file file
file file file
file file
What is a “branch”?

Every time a new commit is made,


the current branch is moved forward
main
branch

New branches can be created, and


Commit Commit Commit multiple branches may even point
f22c9a3 ac901f8 d0a7bc1 to the same commit
$ git branch dev

dev
branch
Checkout operation
$ git checkout dev
$ git checkout ac901f8
$ git checkout main
main
branch

Commit Commit Commit


f22c9a3 ac901f8 d0a7bc1

dev
branch
Staging and committing
Stage modified files individually $ git checkout dev
by name, or all at once with “.” (now make changes to code)
$ git add "file1.txt" "file2.txt"
$ git add .
main $ git commit –m "Commit message"
branch

Then, make a new commit that


Commit Commit Commit Commit
f22c9a3 ac901f8 d0a7bc1 80ce97a incorporates the staged changes

dev
branch

Since the dev branch is


active, it moves forward to
track the new commit
Branching and merging
Git operations
Branching
Switch back to the main branch and
commit different changes

$ git checkout main


main Commit
158ac9e
(now make different changes)
branch
$ git add .
$ git commit –m "Commit message"

Commit Commit Commit


ac901f8 d0a7bc1 80ce97a

dev
branch
Merging
main Git will try to merge the two versions
branch
automatically into a new commit, but
there might be merge conflicts that must
Commit be resolved by hand
Common ancestor 158ac9e
The main branch was merged
into the dev branch
Commit Commit Commit Commit
ac901f8 d0a7bc1 80ce97a cc917de

dev
branch
$ git checkout dev
$ git merge main
Fetching, pulling, and pushing
More git operations
Local and remote repositories
GitHub (remote)

Origin
repository

Your computer will also have a


“working folder (HEAD)” where you There are usually at least two
can view and edit the project code copies of the repository: one on
GitHub, and one in the .git
folder on your computer
Your computer (local)
Working folder (HEAD) .git folder
folder Local
repository
.git folder
file
file
Fetch operation $ git fetch

GitHub (remote)
Downloads new commits from
Origin GitHub to the local repository
repository
Does not affect files in your
working folder (HEAD)

Your computer (local)


Working folder (HEAD) .git folder
folder Local
repository
.git folder
file
file
Pull operation $ git pull

GitHub (remote) Downloads new commits from


Origin GitHub to the local repository,
repository and tries to integrate them
into your working folder

Warning: This operation can


fail if there are merge conflicts

Your computer (local)


Working folder (HEAD) .git folder
folder Local
repository
.git folder
file
file
Push operation $ git push

GitHub (remote)
Uploads commits made in the
Origin local repository to GitHub
repository

Warning: This operation can


fail if there are merge conflicts

Your computer (local)


Working folder (HEAD) .git folder
folder Local
repository
.git folder
file
file
Forking a repository
GitHub (remote)
Project #1 Project #2 (forked from #1)
Forking must be done from
Origin Origin the GitHub interface
repository repository
(it is not a git command)

These two repos are now completely separate


• Different URLs
• Different project pages on GitHub
• Commits to one do not affect commits to the other
Continuous Integration – The practice of regularly
pushing your changes as you work, like multiple times
a day, so the rest of your team can integrate your
changes into their local versions.

Many dev teams adopt the practice


of continuous integration to
minimize merge conflicts
Git terminology
Word Definition

repository A data structure containing an entire project, including every commit made

branch A “version” of the code that is tracked as changes are made

local Your personal computer

remote A cloud-based git server that stores your repository

commit A snapshot of the project codebase at a point in time

push The act of uploading the latest committed version of your branch to the remote machine

pull The act of integrating changes that were pushed by someone else into your local copy

merge The act of combining changes that you made with changes that someone else made

checkout The act of selecting which branch to view and work on

track When a local branch follows along with changes to a corresponding remote branch

fork Making your own personal copy of an entire existing repository

You might also like