Git is a version control system used to manage and keep track of changes in software code. The changes can be hosted on a web platform i.e. GitHub.
These two tools are essential for developers as changes are made in code daily. A basic introduction to git is well outlined here. To perform actions in git, commands are run in a command-line interface known as Git Bash.
By the end of this article, a beginner should be able to make a commit and upload it onto a remote repository i.e. GitHub.
These are the basic terminologies used in git:
- Repository(repo) — a central location where Git stores all the files, folders, and version history of a project.
- Remote repository — a repository hosted on a server or online(web-based) like GitHub where the version history can be saved and interacted with.
- Local repository — a copy of the git repository that resides on the local machine. It contains a git directory(hidden file), commit histories, files, and folders.
There are also some basic commands in git that can be used to make a commit and upload it onto a remote repository — where colleagues can interact with the project. Interaction can be done by analyzing the project and probably making changes and saving the changes made.
Here is a beginner-friendly walkthrough to learn the process of making commits and pushing a project onto a remote repository i.e. GitHub:
Step 1: Create a folder and save it
We assume this folder will contain files of our project and our intention is to track the changes we will make to the project and host them on GitHub — where other colleagues can interact with it.
I will name my folder “First_project”. You can add a file of choice including a .txt file.
Close the folder and navigate to Git Bash.
Step 2: Create a git directory(hidden file) in the saved folder
To do this, navigate into the folder you have created through the command line by;
cd "the_file_path_to_the_folder"
In my Git Bash environment, it will resemble this;
To confirm you are working in the directory, you can use the command;
pwd
The command prints the current directory.
In the current directory, create a git repository(hidden file) in the folder. This is done by initializing using a command;
git init
In my command line;
Step 3: Add the files from the folder that you wish to track
This is done through a command;
git add "name_of_the_file"
In my command line;
Step 4: Check whether the file(s) have been added & ready for commit
Run a command;
git status
In my command line;
To do this, use the command;
git commit -m "include_a_message"
The message is a short description of why the commit is made.
Step 6: Create an empty remote repository on GitHub
On your GitHub account, create a new repository, where the files will be hosted on the remote repository.
You will be directed to this window after creating the repo successfully;
Copy the link displayed, that will be used to create a link between git and the remote repository we created.
Step 7: Create a connection to the remote repo
Use the command:
git remote add origin <the_link_copied_from_github_repo>
On Git Bash:
This creates a connection to the remote repository we created on GitHub.
Step 8: Push the files to GitHub
After creating the connection, push the files to the remote repository by;
git push -u origin
In Git Bash, a successful push command will appear as;
The files are now reflected on the remote repository in GitHub. To confirm this, you can open the remote repository on GitHub and view the files here
They will appear as:
Follow the steps above to track and manage changes in files through git and GitHub.
Top comments (0)