Git Cheat Sheet

Git Cheat Sheet

Have you ever been stuck while using git🤔? If your answer is yes, This article is for you. You don't need to memorize all of the git commands. Here is a cheat sheet that will simplify your life.

What is Git?

Git is a free, open-source version control software. It was created by Linus Torvalds in 2005. Therefore, Git is essentially a content tracker. Git can therefore be used to store content; however, due to its other features, it is primarily used to store code.

Git Cheat Sheet

Initialize a local repository:

git init <directory>

Set configuration value for your username and email:

git config --global user.name <your name>
git config --global user.email <your email>

Clone a repository:

git clone <repository-url>

Add a file to the staging area:

git add <file>

Add all file changes to the staging area:

git add .

Check the unstaged changes:

git diff

Commit the staged changes:

git commit -m "Your Message"

Add changes made to track files and commit:

git commit -a -m "Your Message"

Reset the staging area from the last commit:

git reset <file>

Check the status of the working directory:

git status

Remove a file from the index and working directory

git rm <file>

List the commit history:

git log

To display branches:

git branch

To create a branch:

git branch <branch name>

To switch to a branch:

git checkout <branch name>

To delete a branch:

git branch -d <branch name>

To merge a branch:

git merge <branch name>

Pull changes from a remote repository:

git pull <remote name>

Push changes to a remote repository:

git push  <remote name>

Conclusion

In conclusion, Git is used to track changes in the source code, enabling multiple developers to work together on non-linear development.

Do not hesitate to ask questions or leave comments on this post. I'm available on Twitter, LinkedIn, and GitHub. Keep an eye for my upcoming blog post,in which I will cover another important area of web development. As a developer, I'm glad to provide additional knowledge

Until then, happy coding, and take care!