Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date...
Transcript of Git Presentation - Montana Technological UniversityGit Presentation Author Hunter B Created Date...
GIT PRESENTATIONPRESENTED BY HUNTER BOLES
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
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
GIT ADD, COMMIT, AND PUSH
• I made a file called
README.md, and I want to
push it
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.
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.
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)
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.
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)
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.
I WANT UPDATED BRANCHES!
• Two methods:
• `git pull origin <branch>` updates
a single branch
• `git fetch` updates ALL branches.
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.
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.
THE REPOSITORY IS AT:
• https://github.com/Hunterb9101/example-repo