Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date...

14
GIT PRESENTATION PRESENTED BY HUNTER BOLES

Transcript of Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date...

Page 1: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

GIT PRESENTATIONPRESENTED BY HUNTER BOLES

Page 2: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

LIST OF MY “ESSENTIAL” COMMANDS

• git clone

• git checkout -- <file>

• git add

• git rm

• git commit

• git push

• git checkout <branch>

• git branch

• git branch <branch>

• git status

• git fetch

• git pull origin <branch>

• git stash

• git pop

• git log

Page 3: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

CLONING A REPOSITORY

• Gets an up-to-date copy of the repository, and clones it onto the local

machine.

• Takes one parameter, the .git file path on github/gitlab

Page 4: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

GIT ADD, COMMIT, AND PUSH

• I made a file called

README.md, and I want to

push it

Page 5: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

STAGING AND UNSTAGING

• Definition: Staged files are what are committed, and unstaged files are not

committed when `git commit` is used (think of unstaged as ignored files).

• `git add <files>` stages files for the next commit made.

• `git add .` stages all files in the directory for the next commit.

• `git checkout -- <file>` reverts the file to what it was in the last commit

• DO NOT USE `git rm <files>` to unstage! It acts as a `git checkout -- <file>` AND

an `rm <file>` command.

Page 6: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

GIT COMMIT AND GIT PUSH

• `git commit` makes note of the files changed, like a checkpoint in a game.

• `git commit` DOES NOT mean that it is pushed to the server for everyone to

see.

• `git push` pushes the changes to a remote server.

Page 7: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

BEST PRACTICE FOR COMMITTING

• The best practice is to commit often, and push periodically

• Only commit files which are needed (.o files, password files, and raw data

shouldn’t be committed)

Page 8: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

WHAT AM I ABOUT TO COMMIT?

• `git status` shows all files that

are staged for a commit.

• (I made a new file,

README2.md)

• Notice how the status changes

after I used a `git add`

command.

Page 9: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

I NEED A NEW BRANCH!

• `git branch <branch>` creates a new

branch from the current branch

(master)

• `git checkout <branch>` sets our

current branch to `branch`

• `git branch` shows all branches loaded

onto the local machine (not all of the

branches on remote)

Page 10: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

NOTE:

• Using `git branch <branch>` does not automatically set your branch to the new

branch.

• Branches may be out of date from what is on remote. You’ll need to update these

manually before creating a new branch.

• Untracked files will still exist in the directory when switching branches. (Git doesn’t

know they are there, or if they need to be deleted.)

• Git WILL replace tracked files with the correct version of the file given for the

branch.

Page 11: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

I WANT UPDATED BRANCHES!

• Two methods:

• `git pull origin <branch>` updates

a single branch

• `git fetch` updates ALL branches.

Page 12: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

GIT LOG

• Returns the history for the branch, or a

given file.

• `git log` is for the entire branch

• `git log <file>` is for the given file

(hence why you only commit files you

have changed)

• `git checkout <commit> <file>` can

be used to revert a file to a given

commit.

Page 13: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

SAVE MY CHANGES FOR LATER (ADVANCED)

• `git stash` makes a copy of all given changes, and keeps them for later. (Even

after a branch changes)

• Use `git pop` on the correct branch later to get the changes back.

• Useful when there are multiple issues, one becomes much more important, and

a half-finished product is still waiting to be committed.

Page 14: Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date 10/22/2019 9:27:30 AM ...

THE REPOSITORY IS AT:

• https://github.com/Hunterb9101/example-repo