Beginner guide to GitHub
GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere. This tutorial teaches you GitHub essentials like repositories, branches, commits, and Pull Requests. At the heart of GitHub is an open source version control system (VCS) called Git. Git is responsible for everything GitHub-related that happens locally on your computer. Below, I have listed guidelines for beginners.
Step 1: Install git and create a GitHub account
The first two things you’ll want to do are to download and install git and create a free GitHub account on tour web browser. Configure your git bash by entering your email and user name as asked for when you run the application.
Follow the instructions there while installing Git Bash. To to sign up for GitHub, Open your web browser and search for GitHub. I recommend signing up using google or email to save your time. Use the link below https://github.com/join
Note that for this tutorial we will be using git on the command line only. While there are some great git GUIs (graphical user interfaces), I think it’s easier to learn git using git-specific commands first and then to try out a git GUI once you’re more comfortable with the command. A note: 95% of other online git resources and discussions will also be for the command-line interface.
1: Create a local git repository
When creating a new project on your local machine using git, you’ll first create a new repository (or often, ‘repo’, for short).
To use git we’ll be using the terminal. If you don’t have much experience with the terminal and basic commands, please follow the link below https://www.freecodecamp.org/news/10-important-git-commands-that-every-developer-should-know/
To begin, open up a terminal and and change the directory to desktop using the “cd” command that stands for change directory.
You can now make a directory/folder on the desktop using “mkdir” (make directory) and open it using “cd”.
Using the “touch readme.md”, create a file called readme with a file extension .md. These are text files used as Markdown Documentation Files through Markdown language dialects. MD files are usually saved in plain text format.
Now initialize the project using the “git init “ command and then run the commit command to save it.
2: Add a new file to the repo
Go ahead and add a new file to the project, using any text editor you like though I recommend one to use VS Code or running a touch command. `touch newfile.txt` just creates and saves a blank file named newfile.txt.
Once you’ve added or modified files in a folder containing a git repo, git will notice that the file exists inside the repo. But, git won’t track the file unless you explicitly tell it to. Git only saves/manages changes to files that it tracks, so we’ll need to send a command to confirm that yes, we want git to track our new file.
3: Create a commit
It’s time to create your first commit!
Run the command git commit -m "any message”
The message at the end of the commit should be something related to what the commit contains maybe it’s a about you, maybe it’s a bug fix, maybe it’s just fixing something. Commits live forever in a repository (technically you can delete them if you really, really need to but it’s messy), so if you leave a clear explanation of your changes it can be extremely helpful for future programmers (perhaps future you!) who are trying to figure out why some change was made years later.
4:Create a new branch
Now say you want to make a new feature but are worried about making changes to the main project while developing the feature. This is where branches come in.
Branches allow you to move back and forth between ‘states’ of a project. Official git docs describe branches this way: ‘A branch in Git is simply a lightweight movable pointer to one of these commits.’ For instance, if you want to add a new page to your website you can create a new branch just for that page without affecting the main part of the project. Once you’re done with the page, you can merge your changes from your branch into the primary branch. When you create a new branch, Git keeps track of which commit your branch ‘branched’ off of, so it knows the history behind all the files.
Let’s say you are on the primary branch and want to create a new branch to develop your web page. Here’s what you’ll do: Run git checkout -b <branch name>. This command will automatically create a new branch and then ‘check you out’ on it, meaning git will move you to that branch, off of the primary branch.
After running the above command, you can use the git branch command to confirm that your branch was created:
5: Push a branch to GitHub
Now we’ll push the commit in your branch to your new GitHub repo. This allows other people to see the changes you’ve made. If they’re approved by the repository’s owner, the changes can then be merged into the primary branch.
To push changes onto a new branch on GitHub, you’ll want to run “git push” command. GitHub will automatically create the branch for you on the remote repository: Note that at this stage you have to be connected to internet and logged on to your GitHub account.
You can now check in you GitHub account for any changes.
It has really been a good time for me to talk to you about such a platform for programmers and I will end my case by quoting words of some famous programmers “Make it work, make it right, make it fast.” — Kent Beck