Before I go straight to that Github is a code hosting platform for collaboration and version control. It's a developer tool, however, Github itself isn't much more than a social network like Facebook. You build a profile, upload projects to share, and connect with other users by following their accounts. Not only that but you can also keep text documents and other file types.
You can also use Github without knowing any code at all
The software that runs at the heart of Github is Git. Git is version control software, which means it manages changes to a project without overwriting any part of the project.
Version control is a class of systems responsible for managing changes to computer programs, documents, large websites, or other collections of information. An example is Git.
Setting up Github and Git for the first time.
First, you'll need to sign up for an account on Github.com. it is as simple as signing up for any other social network. To work on your project on your computer, you need to have Git installed. Install Git for Windows, Mac, or Linux as needed.
Now it's time to go over to the command line. On Windows, that means starting the Git Bash app you just installed and on OSX, it's a regular old Terminal. It's time to introduce yourself to Git. Type the following code;
git config –global user.name "Your Name here"
Of course, you'll need to replace "your name here" with your name in quotations.
Next, tell it your email you used when signed up for Github.com. Type;
git config –global user.name "your Email Here"
That's all you need to do to get started using Git on your computer.
Creating your online repository
Now it's time to create a place for your project to live. Both Git and Github refer to this as a repository or "repo" in short, a digital directory or storage space where you can access your project, its files, and all the versions of its files that Git saves.
Go back to Github.com and click the tiny book icon next to your username.
Or go to the new repository page if all icons look the same.
Give your repository a short, memorable name
Go ahead and makes it public just for kicks; why hide your attempt to learn Github?
Don't worry about clicking the checkbox next to "initialise this repository with a README." A readme file is usually a text file that explains a bit about the project. But we can make our own Readme File locally for practice.
Click the green "Create Repository" button and you're set. You now have an online space for your project to live in.
Creating your local repository
So we just made a space for your project to live online, but that's not where you'll be working on it. The bulk of your work id going to be done on your computer. So we need to actually micro that repository we just made as a local directory
First type: mkdir MyProject
mkdir is short for make directory. It's actually not a git command, but general navigation command from the time before visual computer interfaces. So this creates a folder that will have your project.
Next type: cd MyProject
Cd stands for change directory, and it's also a navigation command. We want to go inside the directory we just created.
Next line type: git init
Now we are using the Git command and we know that coz it begins with git .this command stands for "initialise", it tells the computer to recognise this directory as a local Git repository. If you open up the folder, it won't look any different, because this new Git directory is a hidden file inside the dedicated repository.
However, your computer now realises this directory is Git-ready and you can start inputting Git commands.
Now you've got both an online and local repo for your project to live inside.
Next line type: touch Readme.md
This, again, is not a Git command. It's another standard navigational command prompt. touch really means "create." Whatever you write after that is the name of the thing created. If you go to your folder using Finder or the Start menu, you'll see an empty Readme.md file is now inside.
You can clearly see your new Readme file. But can Git? Let's find out.
Type: git status
The command line, usually so passive up to this point, will reply with a few lines of text similar
What's going on? First of all, you're on the master branch of your project, which makes sense since we haven't "branched off" of it. Secondly, Readme.md is listed as an "untracked" file, which means Git is ignoring it for now. To make Git notice that the file is there
Type: git add Readme.md
Notice how the command line gave you a hint there? All right, we've added our first file, so it's time to take a "snapshot" of the project so far, or "commit" it:
Type: git commit –m "Add Readme.md"
The –m flag simply indicates that the following text should be read as a message. Notice the commit is written in the past tense. Always write your commands in the past tense because version control is all about flexibility through time.
Next type: git branch –M main
By default, every git repository's first branch is named
master (and is typically used as the primary branch in the project). As part of the tech industry's general anti-racism work, some groups have begun to use alternate names for the default branch
Now that we've done a little work locally, it's time to "push" our first commit up to GitHub.
Connect Your Local Repository To Your Github Repository.
First, we need to tell Git that a remote repository actually exists somewhere online. We do this by adding it to Git's knowledge. Just like Git didn't acknowledge our files until we used the git add command, it won't acknowledge our remote repo yet, either.
Assume that we have a GitHub repo called "MyProject" located at https://github.com/username/myproject.git. Of course, username should be replaced with whatever your GitHub username actually is, and myproject should be replaced with the actual title you named your first GitHub repository.
git remote add origin https://github.com/username/myproject.git
Now we want to upload, or "push" our changes up to the Github remote repo. That's
Just Type: git push –u origin main
Log into GitHub again. You'll notice that GitHub is now tracking how many commits you've made today. Click on your repository, and it will have an identical Readme.md file as we earlier built into your local repository.
When you want to add other files to the online repository.
Type: touch dogs.txt
We are creating a text file.
Next Type: git status.
Git has not yet noticed that we have put something else. So let's make it notice.
Type: git add .
NOTE: The full stops at git add . Means add everything.
Type: git commit –m "Add file."
Git has now noticed the file.
Now we want to upload, or "push" our changes up to the Github remote repo.
Type: git push
Got to your Github account refresh and click on your repository, and it will have an identical Readme.md file as we earlier built into your local repository.
Ta da! With all of these tools at hand, it's clear that Git and the GitHub service aren't just for programmers.