A Beginner's Guide to Git
By Garen Tyler
This guide gives commands in the Linux / Unix format. They may or may not work on Windows systems.
1 - What is Git?
2 - Git Vocabulary
Git has many terms, but many of them are simple. Services such as GitHub share this vocabulary.
- Repository - Often shortened to repo, a repository is a code project or codebase. Repositories can contain many files and many folders.
- Commit - A commit is a collection of changes to a repo. Changes can be across multiple files.
- Staging - Before adding changes to a commit, the changes must be staged in order to be included in the next commit.
- Push - To add your changes to a remote repo that you have write access to.
- Pull - To get the newest changes to a remote repo that you have read access to.
- Clone - To download a copy of a remote repo locally. Changes you make to your copy do not affect the original.
- Fork - To create your own version of a repo. You own this copy, and can make as many commits to it as you want. If you want to merge your fork with the original, you'll need to create a pull request.
- Pull Request - To ask the owner of a repo to accept your changes.
- Branch - A version of a repo. Repos can have many branches, with differing purposes and code.
3 - Using Git
Git CLI Commands
- Creating a repo - Type
git initto create a repo in the current folder.
- Cloning a repo - Type
git clone repoto clone the repo. Change
repoto the URL of a repository, such as https://github.com/ElementG9/Pivot.
- Staging changes - After making changes, type
git add .to stage all changes. Change the
.to a file name to stage that file.
- Committing changes - After staging your changes, type
git commit -m "commit message"to commit your changes locally. Change
commit messageto something that describes what you changed in that commit. Bad commit messages can make it hard for you or others to see what you changed when reviewing the code later.
- Pushing your changes - To push changes to a remote repo, type
git push origin master.
masteris the default branch name. Change
masterto something else to push to a different branch.
- Pulling changes - To pull changes to a repo, type
git pull origin master.
mastercan be changed to pull from a different branch.