Introduction
In this article, readers will learn how to use Git and GitHub to improve their workflow.
At different points in a creator's life, there could be a series of undoing and redoing. The idea of version control (tracking and managing changes to a file) can help with this, as the creator adds/removes parts of their program. Being conversant with Git and GitHub will make this possible.
Table of Content
- Prerequisite
- What is Git?
- What is GitHub?
- Creating a GitHub Repository
- Git first steps
- GitHub Desktop first steps
- Creating a
README.md
file -
Understanding Basic Commands (
add
,commit
, andpush
) - Conclusion
Prerequisite
To follow along with this article;
- create an account on GitHub
- download and install
- Git, if you prefer to use a CLI (Command Line Interface), or
- GitHub Desktop, if you prefer to use a GUI (Graphical User Interface).
What is Git?
Git is a version control system (a system that helps users refer to previous versions of their work, if need be). It is a software that tracks changes made to files. It runs on the command line and is mostly preferred by creators who work on a CLI like Software Engineers, Web Developers, System Administrators, and Programmers.
What is GitHub?
GitHub is a website that houses repositories (a top-level folder structure containing sub-folders and files). The repositories are stored remotely (on the website), so, users will need a means to work on them locally (on their computers). This is where Git (a CLI) and the GitHub desktop application (a GUI) come into play. The desktop application is usually preferred by non-programmers.
GitHub also allows for collaboration, which makes it useful for networking, and for team members to work together.
Creating a GitHub Repository
Click on the button and follow the steps to create a GitHub repository:
Git first steps
Git is a software installed and operated locally. You need a way for it to track the remote repository you're currently working with to upload your files to the correct location. To do this, you set your email and name, after which you choose the remote repository to track by initialising or cloning it.
Setting your email and name
To set up your email and name on Git to match with your GitHub account, run the following command:
git config [--global] user.email "user@email.com"
git config [--global] user.name "first_name last_name"
The command in the square brackets is optional and is used to set the email and name globally on your machine. Omitting the --global
option sets the email and name for only the current repository.
The optional commands are to be run without the square brackets.
Initialising/Cloning a repository
To create a local repository to track the remote repository, you can either initialise or clone it. To initialise a folder on your machine as a Git repository means to point it to a remote repository. Navigate to the folder you wish to initialise and run this command:
git init
How to initialise a repository on the terminal
To clone a remote repository means to copy the folder structure to your local machine. You would need the remote repository URL to clone it.
git clone https://github.com/owner/repo.git
How to clone a repository on the terminal
GitHub Desktop first steps
GitHub Desktop provides users with a GUI, giving non-programmers a way to access GitHub's features. Launch the GitHub Desktop app and sign in to your account.
How to configure GitHub Desktop
Creating/Cloning a repository
After signing in to your account on the GitHub Desktop application, creating and cloning a repository can be done with the click of a button.
- Creating a repository
How to create a repository on GitHub Desktop
- Cloning a repository
How to clone a repository on GitHub Desktop
Creating a README.md
file
A README.md
file is a file written in Markdown syntax and is used to give information about a repository. Upon creating a repository, the option to initialise a README.md
file is available, but it can also be created locally. Creating this file is the same as creating any other file but with the name README
and the file extension .md
. The name of this file is by convention, as the repository will use any other markdown file for information about the repository if the README.md
file is unavailable.
To learn how to write in markdown syntax, check out this article
Understanding Basic Commands (add
, commit
, and push
)
After creating/initialising/cloning a repository, you can now create files, make edits, and continue being creative. These files should communicate with GitHub to make use of the version control system, and also for collaboration. There are three basic commands used for this; add
, commit
, and push
.
These operations are available through point and click on the GitHub Desktop application. Git users will have to prefix these commands with the git
command.
add
The add
command is the first step and is used to add file(s) that will be included in a project's history.
# To add selected files
git add file_1 file_2
# To add all files
git add .
commit
The commit
command is the second step and is used to record the changes made to the files that have been added.
git commit -m "A simple descriptive message"
push
The push
command is used to update (publish) the remote repository with all changes made to the local repository.
git push
How to add, commit, and push on the terminal
Conclusion
As you have seen, using Git and GitHub is easy and fun. From creating a GitHub account, creating a repository, and initialising or cloning a repository, to the basic add
, commit
, and push
commands, you should now be comfortable using version control with your projects.
Resources
For more reading, you can check these out:
Top comments (0)