Git is software for tracking changes in any set of files, usually used for coordinating work among programmers and collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows (thousands of parallel branches running on different systems).
commit
your code to take a snapshot of a project. You can then rollback in case you screw up.Version Control: A category of software tools that help a software team manage source code over time.
Repository (aka repo): The root directory of a project that Git tracks.
Local Repository: A repo on your local machine.
Remote Repository: A repo on another machine or server (such as GitHub).
Branching
: A version of the repo that diverges from the main working project.
cloning
: The action of copying a remote repository into a local environment(your computer). You can clone your repository to create a local copy on your computer and sync between the two locations.
commit
changes: Saving a snapshot of your project.
add
changes: An extra step you need to complete before you can commit a change (for safety).
push
changes: Send local changes to your remote repo.
pull
changes: Retrieve remote changes to your local repo.
main
: The primary branch of all repositories
Git uses SHA-1 hashes to refer to the commits. Each unique hash points to a particular commit in the repository.
Using hashes, Git creates a tree-like structure to store and retrieve data easily.
Git takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
The files in each Git project go through several stages:
Working directory: Modified files, but untracked and not yet ready for commit.
Staging directory: Adding modified files to the staging environment means they are ready for commit.
Committed: Snapshots of files from the staging area saved in the commit history.
Git keeps track of each line of code in your project, including:
A typical sequence of events in a developer's day, they:
add
the changes to "staging";commit
the changes to save a "snapshot" of the project;push
the changes to a Remote Repo (i.e. GitHub) when the changes are ready to be shared or deployed.pull
any new changes from the Remote Repo before you can push
. This is when dreaded merge conflicts need to be handled.Some things to think about when first learning Git:
add
your changes before you commit
them.Don't forget to add the -m "commit message here"
when committing changes.
$ git commit -m "updated About page"
Otherwise, your terminal will open a vim window so you can add the mandatory commit message. It's the default command line text editor on most systems and is not the most intuitive application to use.
:q!
will quit without saving so you can try committing again with the -m
flag.:wq
will save the file before you quit. This is handy if you're merging changes from multiple machines.