Git Commands To Know As A Developer [Cheatsheet for Beginners] 👨‍💻📑

Arjun Vijay Prakash - Aug 25 '23 - - Dev Community

Done with remembering Git commands? Check out this cheat sheet with 10 commands to make your life easier as a code newbie.

You before this post -
ImageYou after this post -
Image

Some Simple Git Terms To Know:

  • Repository: This is where all your project's files, changes, and different versions are stored.

  • Branch: It's like a separate copy of your project where you can work on a specific version. The main branch is often called "master."

  • Commit: Think of it as a single snapshot of the changes you've made to your project in a branch.

  • Checkout: This is how you switch between the current version you're working on and another version in your project.

  • Master: The main version of your project, usually referred to as the "master" branch.

  • Merge: When you combine changes from one branch into another to keep everything up to date.

  • Fork: A clone of a repository that you can work on independently.

  • Head: The most recent snapshot of your project that you're currently working with.

Fundamental Git Commands You Need to Grasp

git init | git init [folder]
Enter fullscreen mode Exit fullscreen mode

To start a new project or set up version control in an existing project, you use this command. It creates a repository either in the current folder or the specified folder.

git clone [repo URL] [folder]
Enter fullscreen mode Exit fullscreen mode

This command copies an existing repository to your computer. If you provide a repo URL, it copies to the current location. If you want it in a different location, include a folder path.

git add [directory | file]
Enter fullscreen mode Exit fullscreen mode

When you want to prepare changes to be saved, this command comes in handy. It stages the changes in a directory or a file. Usually followed by git commit and git push.

git commit -m "[message]"
Enter fullscreen mode Exit fullscreen mode

After staging changes, this command commits them with a message explaining the changes. You can also use -am to add and commit changes together.

git push
Enter fullscreen mode Exit fullscreen mode

To send your committed changes to the main repository, you use this command.

git diff
Enter fullscreen mode Exit fullscreen mode

To see the differences between your current changes and the last committed version, you use this command. You can also compare staged changes with the latest version using -staged, or specify a file to compare.

git pull
Enter fullscreen mode Exit fullscreen mode

This command is used to fetch changes from the original branch and merge them into your local branch.

git fetch
Enter fullscreen mode Exit fullscreen mode

Similar to git pull, this command gets the latest changes from the main branch, but it doesn't automatically merge them.

git log
Enter fullscreen mode Exit fullscreen mode

This shows the history of your commits in a default format, letting you see what changes have been made over time.

git status
Enter fullscreen mode Exit fullscreen mode

This helps you know the status of your files, whether they're ready to be committed, changed, or untracked.

Use this official cheatsheet of Git for more commands.

I hope this article has helped you in learning about Git. Thanks for reading the article! Don't forget to bookmark this post for reference in the future!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .