It’s been an exciting first week at Flatiron School!
By far the most confusing thing for me to date has been Git. So I’m going to dump everything I know to this post, in the hopes that trying to explain the various Git commands will help me understand them a little better.
My apologies for any blindingly basic errors – it’s my first week. Corrections are appreciated and welcome.
What is Git?
A less Potter-centric way of putting it is that Git is a version control system. It allows you to manage a set of files as they change over time.
Git is a distributed system. This means that each user in the system can have their own repository on their local system that is a fully functioning clone.
repository: The data structure for a set of fully functioning files. It contains the history, changes over time and various project branches of the files. A horcrux.
staging area: A place to make changes on files without commiting to making those changes permanent. A sandbox.
HEAD: Git tracks the changes in your files over time. HEAD is a symbolic reference that points to the version of your files that you are currently working with. By default, it is the most recent commit in your current branch.
master: If Git is visualized as a tree, master is the trunk. It’s just another repository, but it is used as the most stable version of the files, which all the other branches diverge from and return to once their purpose is complete.
branch: Unsurprisingly, if master is the tree’s trunk, then branches are… the tree’s branches. Branches let you work on multiple disparate features at once.
origin: The default name of the remote git repository you cloned from is called “origin”.
fast forward: The simplest merge in git, where only one of the two branches has changed and there are no conflicts.
Basic Git commands:
add: Moves the current version of the named file to a special staging area, holding files that are ready to be committed.
branch: Allows you to list, create and manages branches within git.
checkout: Switches to a new branch. With the -b flag, creates a shortcut to create a new branch and switch to it.
clone: Makes a copy of a git repository.
commit: Records a snapshot of the staging area, and moves HEAD to the new commit.
config: Allows you to configure your git.
diff: Shows the changes between two branches.
fetch: Updates your repository from another one, pulling down any data that you do not have locally.
init: Creates a new repository from an existing directory of files.
log: Lists the commits made in the current repository.
merge: Combines the changes in your current branch with another one.
pull: This command will basically run a git fetch immediately followed by a git merge.
push: Pushes your repository’s new branches and data to a remote repository.
remote: Allows you to list, add, and delete remote repositories.
reset: Allows you to undo commits.
rm: The git analog to the BASH rm command, git rm will remove files from the staging area.
status: Shows the status of the files in your working directory and staging area.
Some useful sources:
Make yourself useful.