Version control (sometimes called source control) keeps track of changes to files over time. Multiple users can edit the same projects. Some platforms that support version control are GitHub, GitLab, BitBucket, and Google Drive.
Git is an open source tool, but platforms like GitHub and GitLab integrate with git by hosting the repositories (project folders). Repositories can also be self-hosted and use git for management through other services. This post is structured GitHub, a popular platform for many developers. Keep in mind that other repository storage platforms have nuanced differences (e.g. GitHub UI drag and dropping existing files will track code changes, whereas GitLab UI drag and dropping existing files will assume the file is overwriting everything–history included).
Repository (aka repo) - a project folder that tracks changes in the subdirectories and files, a collection of files Commit - sometimes considered snapshots of edits made complete with time, a hash reference, message, and the edits themselves Pull - a command to retrieve the latest edits from the repository Push - a command to push the latest edits (packaged in a commit) to the repository README.md - a file that describes how to use the project, FAQ, and/or explains what the repository is about Branch - a development path, all paths branch from main Clone - a copy of a repository often including a link to the original repo (remote) and past commits .gitignore - a file that filters what files end up on GitHub (files like .c, .java, .md, etc.) and what don’t (e.g. compiled object files, secret keys, binary files) Merge Conflict - when edits are made at the same place (and time) and a conflict occurs Fork - a clone, but set up in a user’s profile linking back to the original repo Rebase - the process of combining (“replaying”) commit(s) into a new commit (often used when resolving merge conflicts) Stage - the action of preparing file(s) to be committed
git status
get an update of what files have been changed or are untrackedgit add <filename, ., *>
add changed files to stage a commitgit commit -m “Commit message here”
add a message to a commitgit push
push a staged commit to the central repositorygit pull
retrieve the latest changes from the central repositorygit reset --hard HEAD
reset all files to the last commitgit checkout branchName
/ git switch branchName
switch to a different development pathgit checkout -b newBranchName
switch to a new development path (git branch newBranchName
+ git checkout newBranchName
)git merge main
to reduce merge conflictsStackOverflow is great for fixing git things. However, git is an extremely powerful tool, and it is easy to wipe the entire edit history or cause irreversible change. With great power comes great responsibility. Never automatically follow instructions on fixing things in git without understanding what each command does. Edit history can be rewritten in git, but it may not be the rewrite needed. If comamnds are confusing, spend the time to figure it out, ask another git user, or try to find another way. Just don’t do everything the internet says and lose the whole project and be unable to get it back, that defeats the whole point of version control.
Push to the development branch often/commit regularly. Not only to save changes but to ensure if others are on the branch they can pull each other’s changes and everyone can reduce their merge conflicts.