Git and GitHub have been excellent tools for applying version control to my workflow. GitHub is where I have my remote repositories these days.
What is version control: Version control tracks and manages changes to files over time, allowing collaboration, rollback, and maintenance of a complete history.
Created by Linus Torvalds in 2005, Git started out being used for all who were contributing to and collaborating on the development of the Linux kernel.
For getting started with Git, I am going to share 2 foundational commands and a simple workflow I use to begin version control with my projects, leveraging remote repositories.
One can find ways to use a gui, but I prefer to do this in the terminal.
Benefits of using/starting in the terminal: It provides a deeper understanding of core concepts, greater control, and faster workflows. It ensures consistent cross-platform usage, better troubleshooting, and easier integration with advanced tools. Starting with the terminal builds a strong foundation, making one a more proficient and confident Git user.
Ok, assuming Git is installed on your machine.
1. git init
In a new or existing project directory run the command git init
.
This will initialize a new Git repository, enabling version control by creating a hidden .git folder.
my-project/
└── .git/
*The .git is the hidden directory that Git uses to store all version control information.
Create a repository in GitHub or a Git platform of your choice. The examples here will be for GitHub.
On the newly created repo page, copy the address of the repo.
Let's say your username is trinity and your repo is called matrix. The address would be: https://github.com/neo/matrix
Now clone the remote repo to the local Git repo.
2. Git Clone
In the directory where you ran git init
, run the following command:
git clone https://github.com/trinity/matrix.git
Git clone will copy the remote repo to your machine.
Now it's off to the races, and one is ready to start working on the project locally.