For any programmer, version control is becoming an indispensable tool today !!
If you want to learn Git from basic, you have come to the right blog
GIT for Beginners This is a wide beginner’s guide. There are lots of clients for Git but in this blog, we focus on Github. This blog is a git cheat sheet for beginners .
What is Version Control !!
A version control system is a type of software tool that helps the software team manage changes to the source code over time. If an error occurs, the developer can reverse the time and compare the code of the earlier version to help fix the error while minimizing interference with all team members.
The most widely used version control system today is Git. Git is a distributed version control system. This means that each developer’s working copy contains the complete version history of the software (centralized repository) and the complete history of all changes. It helps to track changes Therefore, any time you add new code if you encounter a fatal error and you don’t know what the error caused, then you can revert to the stable state. it very helpful for debugging your code keep track of code changes over time. Git is designed with performance, security, and flexibility in mind. Therefore, the most popular and most commonly used.
Git can also help you synchronize code between multiple people. So imagine that you and your friend are working on a project. You are all working on the same project file. Git now merges the changes made independently by you and your friends into one “master” repository. Therefore, by using Git, you can ensure that you are all using the latest version of the repository. Therefore, you don’t have to worry about sharing documents with each other to maintain the workflow.
Let’s start practicing some commands
First of all, make an account on GitHub. if you already have moved to the next step.
Configure your email credentials globally. These credentials are used during the commit.
$ git config – -global user.name “Alexa”
$ git config – -global user.email “[email protected]”
if you want to set credentials for the current repository, use the above command without – -global.
Inside the project folder, put the below command for configuring the remote URL.
$ git init
$ git remote add origin <REPO_URL> //add origin
Some basic commands which every beginner should know
git add . or git add <SPECIFIC_FILE/DIRECTORY>is a command used to add a file that is in the working directory to the staging area.
git commit or git commit -m "YOUR COMMIT MESSAGE"is a command used to add all files that are staged to the local repository.
git push or git push -u origin <BRANCH_NAME>is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository.
git fetchis a command used to get files from the remote repository to the local repository but not into the working directory.
git mergeis a command used to get the files from the local repository into the working directory.
git pull or git pull origin <BRANCH>is a command used to get files from the remote repository directly into the working directory. It is equivalent to a
git fetchand a
After getting some basic knowledge about git, now it’s time to move to learn some advanced commands.
$ git statusThe git status command displays the state of the working directory and the staging area.
$ git helpGet help with git commands
$ git remote -vList down all remotes
$ git remote rename <old-name> <new-name>Rename a remote
Branching in Git
A branch is a different version of the repository from the main work item. This is a feature available in most modern version control systems. A Git project can have multiple branches. These branches are pointers to snapshots of changes when you want to add new features or fix bugs. Therefore, merging unstable code with the main codebase is complicated and also helps you clean up future history before merging with the main branch.
$ git branchList branches
$ git branch -aList all remote branches
$ git branch <new_branch_name>Create new branch
$ git branch -d <branch>Delete branch
$ git branch -D <branch>. Force delete branch
$ git branch -m <rename_branch>Rename branch
$ git checkout <branch>Switch branch
$ git checkout -b <new_branch_name>Create and Change branch
$ git push origin --delete remote-branch-nameDelete remote branch
Download git cheat sheet for beginners
For practice git command: Github practice
For practice Git Branching: Git Branching
If you want to do an online certification course, visit the Udemy git course
Youtube video for basic git concept Telusko video