DEV Community

Cover image for Git Commands You Need for Hacktoberfest 2024 - Git cheat sheet
Pratap Parui
Pratap Parui

Posted on

Git Commands You Need for Hacktoberfest 2024 - Git cheat sheet

Hello, aspiring developer!

Are you ready to level up your GitHub skills and make an impact in the open-source world? As Hacktoberfest is in full swing, and we’re just two weeks in, there's no better time to start contributing and boosting your expertise.

I know it’s been a while, but I’m excited to share some cool content I’ve been working on, and from now on, I’ll be posting regularly.

So, get ready for an exciting journey that will take you from a beginner to a Hacktoberfest pro. Let’s dive in and explore the world of Git commands together!

Configure name and email with Git

If you are a beginner into this git and github things and if you just install the git for first time or say on a new machine then you need to configure some data to use the git into your local system. Here are the few steps which you can follow copy paste the below command into your any terminal and make sure you change the user.name and user.email with your actual details

# set name and email (example name and email Id)
git config --global user.name "paruidev"
git config --global user.email "pratap@paruidev.com"

# set default branch name (optional)
git config --global init.defaultBranch main
Enter fullscreen mode Exit fullscreen mode

Simple Git Workflow

Cloning a Repository

Clone a remote repository to your local machine, bringing the entire project history and all its branches to your computer. This allows you to work on the project offline and contribute changes back to the original repository.

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

You can copy the repository URL from the repo's GitHub page.

Check Repository Status

Check the status of your working directory to see which files have been modified, added, or deleted since your last commit. This command provides a snapshot of your current project state, helping you track changes and prepare for staging.

git status
Enter fullscreen mode Exit fullscreen mode

This command shows which files are changes, which ones are added for committing, etc.

Adding Changes

Stage changes by adding files to the staging area in preparation for committing. This crucial step allows you to selectively choose which modifications you want to include in your next commit, giving you fine-grained control over your version history. By staging changes, you can review and organize your work before permanently recording it in the repository.

git add <file-name>
Enter fullscreen mode Exit fullscreen mode

Commit Changes

After staging, commit changes with a meaningful message.

git commit -m "Commit message"
Enter fullscreen mode Exit fullscreen mode

Viewing Commit History

Check your commit history.

git log
Enter fullscreen mode Exit fullscreen mode

For a simpler, one-line format:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Push Changes to Remote

Push committed changes to the remote repository.

git push
Enter fullscreen mode Exit fullscreen mode

Create Branches and Merge it

Branching allows you to work on different parts of your project independently. Here's how to manage branches:

Create a New Branch

Create a new branch for your feature or bug fix.

git switch -c <branch-name>
Enter fullscreen mode Exit fullscreen mode

If you just want to create the new branch and don't want to switch to it:

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

Switch to Another Branch

if you want to switch to another branch

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

List All Branches

See all branches in your repository.

git branch
Enter fullscreen mode Exit fullscreen mode

Merge a Branch

Merge changes from one branch into your current branch.

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

Delete a Branch

Once a branch is no longer needed, you can delete it. but make sure once it done it can’t be revert back. So do with your own risk.

# Locally
git branch -d <branch-name>

# Remotely
git push origin --delete <branch-name>
Enter fullscreen mode Exit fullscreen mode

Save Code in Stashing.

Stashing temporarily stores your changes without committing them.

Save Changes to a Stash

If you're working on something and want to switch branches without committing:

git stash
Enter fullscreen mode Exit fullscreen mode

Apply Stash

To retrieve your changes later:

git stash apply
Enter fullscreen mode Exit fullscreen mode

List Stashed Changes

If you have multiple stashes, you can see them with:

git stash list
Enter fullscreen mode Exit fullscreen mode

Hacktoberfest is more than just a month-long event—it's an opportunity to grow and give back to the developer community. With this cheat sheet, you're equipped to tackle GitHub challenges head-on.

Remember, every contribution counts, so dive in, learn, and enjoy the journey!. Let me know how many repository is approved till now done with your hacktober fest contribution and which types of repository you’ve contributed to I'm exited to know about it.

Explore paruidev for in-depth guides & some tip and tricks. Also If you all have any quires and doubts feel free to have your questions into comment section I'm happy to help you.

Happy Hacking all of you!

Top comments (0)