Git and GitHub in a nutshell
Hey Guys!
So this is my first technical article and I’m super duper exciteddddd!!!. I’m sure you are wondering why I am so excited about this, well git and git hub was one of the first challenges I faced as a newbie in tech it was a nightmare. Even my mentors still tease me about it till now.
The first time I saw someone typing commands on git bash I was like whatttt??
Like how am I suppose to know this everything seemed like magic but guess what I can use git and git hub easily now and I’m glad I will be able to help newbies in tech with this article and save them the stress I went through.
So let go straight to my article…
DRUM ROLLSSSSSSS!!!
This is a guide for beginners and intermediate developers that don’t know what git is or just used it briefly but still, dint grasps the full concept of it.
Why is git and git hub important?
Git allows a team to efficiently and effectively contribute code to the same project in an asynchronous way. This empowers teams to collaborate better and thus allows them to solve bigger and more complex problems.
What is git?
Git is a Distributed Version Control System(VCS) for tracking changes in computer files. It was created in 2005 by Linux Torvalds who is also the creator of Linux.
Git is a decentralized version control system that is many developers can work on the same project without being on the same network. Git helps us manage our project files, one of the primary reason why git exists is to keep track of the entire history of your projects.
Git coordinates work between multiple developers and it tracks every single version and every single change that is made on the project e.g who made what changes and when it occurs. You can also revert back to any specific version of any file at any time as long as it was committed to the repository
Usually, when you use git you will have a repository on your local machine that you work on, you make changes and then you upload/push to a remote repository e.g Github, bitbucket and then you can push your local repository to remote repository e.g Github.
You don’t need an internet connection to work on a local repository but you need internet to push it your remote repository.
Concepts of git
- It Keeps track of code history by taking snapshots of your files.
- You decide when to take a snapshot by making a “commit”.
- You can visit any snapshot at any time and you can also revert back if you need to. Your code is safe while working with git.
- You can stage files before committing by simply saying add command
- Once you make a commitment to a remote repository other developers can pull that information to their machine.
- You can also create a branch while working on a project.
Github
Github is a web-based service for version control using Git. Basically, it is a social networking site for developers. You can look at other people’s code, identify issues with their code and even propose changes. This also helps you in improving your code. On a lighter note, it is a great place to show off your projects and get noticed by potential recruiters.
- In short, Git is a Version Control System and GitHub is a hosting service for Git Repositories.
Basic Terminology
Repository: A Git Repository, or repo, is a folder that you’ve told Git to help you track file changes.
Branch: A branch is an independent line of development. You can think of it as a brand new working directory.
Fork: A fork is a personal copy of another user’s repository that lives on your account.
Clone: A clone is simply a copy of a repository that lives on your computer instead of on a server.
Commit: A commit is a set of one or more changes to a file(or a set of files). Every time you save, it creates a unique ID(“hash”) which helps it keep track of the history.
Master: The default development branch. Whenever you create a git repo, a branch named “master” is created which becomes the default active branch.
BASIC COMMANDS.
$git init
This will initialize a git repository, so you go into your folder via your command line or terminal and you call git init this will create a .git folder in that project but it is hidden by default once you initialize that folder as a repository you can then start to run other commands.
$git add<file>
This will add the file or files that you specify to the staging area on the index they will then be ready to commit you can run this command as many time as you need to before committing, it will just keep the file in that staging area
$git add.
This automatically adds all files without specifying the staging area on the index.
$ git status
If you want to see what you have in the staging area and ready to commit you can just use git status and that will display the differences between the working tree and then the staging area on the index.
$git commit -m “message”
When you are ready you can go ahead to commit your files so you run git commit and that will take everything that is on the index in that staging area and push it to the local repository.
$git push
This will take the local repository that you have created and push it to the remote repository such as git hub. You will have to add your login details.
$git pull
If you want to pull the latest changes from a remote repository you can just do a git pull so if someone makes a change and you want the latest version you can just use git pull.
$git clone(URL of the repo)
This will copy a remote repository into your current folder, so if you find a project you like on Github you can simply clone it and that will download it to your machine.
HOW TO CREATE A BRANCH
$git branch<branchname>
Branches can be created using the git branch command.
$git push origin <branchname>
Use the git push to save your changes on the server.
$git pull origin master
To keep the local repository in sync with the remote repository.
Conclusion
There are a lot more commands to learn but these are enough to get you started. You can pick up the rest of the commands as you explore and use git and Github more.
Once you master all of this using Git and GitHub won’t be a problem. It isn't time-consuming.
I hope my article was helpful. I will be glad if you can share your thoughts with me on Twitter @zei_na_b.