DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Git cheat sheet (Part 1)
Ajiboso Adeola
Ajiboso Adeola

Posted on

Git cheat sheet (Part 1)

Have you ever been stucked while using gitπŸ€”? If your answer is yes, This article is for you. You dont need to memorize all of git command. Here is a cheat sheet that will simply 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

Initialze a local repository:

git init <directory>
Enter fullscreen mode Exit fullscreen mode

Set configuration value for your usernmae and email:

git config --global user.name <your name> 
Enter fullscreen mode Exit fullscreen mode
git config --global user.email <your email>
Enter fullscreen mode Exit fullscreen mode

Clone a repository:

git clone <repository-url>
Enter fullscreen mode Exit fullscreen mode

Add a file to the staging area:

git add <file>
Enter fullscreen mode Exit fullscreen mode

Add all files changes to the staging area:

git add .
Enter fullscreen mode Exit fullscreen mode

Check the unstaged changes:

git diff
Enter fullscreen mode Exit fullscreen mode

Commit the staged changes:

git commit -m "Your Message"
Enter fullscreen mode Exit fullscreen mode

Add changes made to track files and commit:

git commit -a -m "Your Message"
Enter fullscreen mode Exit fullscreen mode

Reset staging area from last commit:

git reset <file>
Enter fullscreen mode Exit fullscreen mode

Check the status of the working directory:

git status
Enter fullscreen mode Exit fullscreen mode

Remove a file from the index and working directory

git rm <file>
Enter fullscreen mode Exit fullscreen mode

List the commit history:

git log
Enter fullscreen mode Exit fullscreen mode

To display branches:

git branch
Enter fullscreen mode Exit fullscreen mode

To create a branch:

git branch <branch name>
Enter fullscreen mode Exit fullscreen mode

To switch to a branch:

git checkout <branch name>
Enter fullscreen mode Exit fullscreen mode

To delete a branch:

git branch -d <branch name>
Enter fullscreen mode Exit fullscreen mode

To merge a branch:

git merge <branch name>
Enter fullscreen mode Exit fullscreen mode

Pull changes from a remote repository:

git pull <remote name>
Enter fullscreen mode Exit fullscreen mode

Push changes to a remote repository:

git push  <remote name>
Enter fullscreen mode Exit fullscreen mode

Conclusion

Git is used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to tracking changes in the source code, enabling multiple developers to work together on non-linear development.

I hope you found this article helpful in understanding Git command. Follow me here on Dev or Twitter for more updates 😊

Top comments (5)

Collapse
 
favouritejome profile image
Favourite Jome

Well done Adeola πŸŽ‰

Collapse
 
comfortdeola profile image
Ajiboso Adeola

Thank you

Collapse
 
error12p profile image
Paula

Thanks for the summary. It's good to have on hand. πŸ‘Œ

Collapse
 
atandaoluwatunmise profile image
Tunmise Atanda

Well done Adeola, this was quite impactful

Collapse
 
comfortdeola profile image
Ajiboso Adeola

Thank you

Why You Need to Study Javascript Fundamentals

The harsh reality for JS Developers: If you don't study the fundamentals, you'll be just another β€œCoder”. Top learnings on how to get to the mid/senior level faster as a JavaScript developer by Dragos Nedelcu.