Login
A chronicle of the thoughts, learning experiences, ideas and actions of a tech junkie, .NET, JS and Mobile dev, aspiring entrepreneur, devout Christian and travel enthusiast.
GIT - For The Absolute Beginner (Part 2)
As a sequel to this post on the common git commands that you would find helpful in your workflow, this post aims to be a glossary of technical terms used when working with git in particular but could also apply to other version control systems. In this tutorial, I would be taking you through a simple git setup from beginning to end. We would initialize the git repository, add files to it, add remotes, and push code to origin
. Future articles would deal with adding a gitignore
file, removing files from tracking, branching, setting an upstream and pulling from origin
.
Requirements
To follow this tutorial, two pieces of software are necessary and one is optional but recommended.
sudo apt-get install git
for Debian based distributions and sudo yum install git
for Fedora-based distributions.Visual Studio Code
based on personal experience. It can be gotten here (for Windows, MacOS and Linux). The text editor would be used for working on the files we’ll add to tracking.Procedure
git config --global user.name "John Doe"
This command is for you to set your name as you want it to reflect on the remote sites you would be pushing your code to. The John Doe
is an example and/or placeholder and should be replaced with your name.
git config --global user.email "john@doe.org"
As was stated for the previous command, the john@doe.org
is also a placeholder and you should be replaced with the email address that you used for the online version control system registration.
With that out of the way, we go ahead and create a folder that would contain our code. Create a folder named git-workflow
NB: creating folders on each OS platform is different, so I would leave it to you to do.
Next open that folder in the terminal (for macOS and Linux users) or the command prompt (for the Windows users). I created my folder in the Documents directory on my Mac, so to get into that folder, I would run the command:
cd /Users/winner-timothybolorunduro/Documents/git-workflow
git init
this gives an output in the terminal similar to this:
Initialized empty Git repository in /Users/winner-timothybolorunduro/Documents/git-workflow/.git/
code .
this starts the visual studio code and opens the folder in the app. Create three files, index.html
, styles.css
and script.js
. These files would be what we add to tracking.
add
command and pass the files to be tracked as arguments. In this instance, we would run:git add index.html
git add styles.css
git add script.js
git commit -m "added code files"
When clicked, an interface such as the one below is displayed.
Fill in git-workflow
for the repository name and click the "create repository" button.
Copy the link shown in the text box and proceed to the next step.
git remote add origin https://github.com/bolorundurowb/git-workflow.git
git push origin master
The push
command is used to send commits from the local machine to a remote branch. Once this is done, we refresh our repository’s GitHub page and we’ll see our code files there.
And this is what my terminal looked like after running the commands:
With that we come to the end of an initial dip into git and version control in general. My next article would get us into things like branching. I’d love to hear your feedback and suggestions in the comment section. Have a great time learning.
Comments