Git Commands Guide - bounswe/bounswe2025group8 GitHub Wiki

Git Commands Guide

Welcome to our Git commands guide! This is a place where you can quickly find the most useful Git commands without digging through long documentation. Whether you're new to Git or just need a refresher, this page should help.


Getting Started

Initialize a repository

πŸ”Ή git init β†’ Creates a new Git repository in your current folder.

Example:

cd my-new-project
git init

Clone an existing repo

πŸ”Ή git clone <repo-url> β†’ Copies an existing Git repository to your local machine.

Example:

git clone https://github.com/user/project.git

Tracking Changes

Check the status of your files

πŸ”Ή git status β†’ Shows what’s changed, what’s staged, and what’s untracked.

Stage changes

πŸ”Ή git add <file> β†’ Moves a file to the staging area.

Example:

git add index.html

Commit changes

πŸ”Ή git commit -m "your message" β†’ Saves the staged changes with a message.

Example:

git commit -m "Fixed the navbar layout"

Try to write clear and descriptive commit messages!

View commit history

πŸ”Ή git log β†’ Displays a list of past commits.


Branching & Merging

Create a new branch

πŸ”Ή git branch new-feature β†’ Creates a new branch.

Switch to a branch

πŸ”Ή git checkout new-feature β†’ Moves you to the specified branch.

Shortcut:

git checkout -b new-feature

Merge changes from another branch

πŸ”Ή git merge new-feature β†’ Merges the new-feature branch into your current branch.

Example:

git checkout main
git merge new-feature

πŸ‘‰ Always check git status before merging to avoid conflicts.

Delete a branch

πŸ”Ή git branch -d new-feature β†’ Deletes a branch after merging.


Working with Remotes

Link a remote repository

πŸ”Ή git remote add origin <repo-url> β†’ Links your local repository to a remote one.

Push your changes

πŸ”Ή git push origin main β†’ Sends your local commits to a remote repo.

Pull the latest changes

πŸ”Ή git pull origin main β†’ Fetches and merges updates from the remote repository.

Fetch changes without merging

πŸ”Ή git fetch origin β†’ Retrieves remote changes without merging them.


Undoing & Fixing Mistakes

Unstage a file

πŸ”Ή git reset <file> β†’ Removes a file from staging but keeps the changes.

Discard local changes

πŸ”Ή git checkout -- <file> β†’ Resets a file back to the last committed state.

Undo a commit

πŸ”Ή git revert <commit> β†’ Creates a new commit that undoes a specific commit.

Reset to a previous commit

πŸ”Ή git reset --hard <commit> β†’ Resets your repo to a specific commit and deletes all changes after it.


Helpful Tips

βœ… Commit often – Small, frequent commits are better than one giant commit.
βœ… Use branches – Keep your main branch clean by developing features in separate branches.
βœ… Pull before pushing – Always run git pull before git push to avoid conflicts.
βœ… Write meaningful commit messages – Make sure your commit messages clearly explain what changed.
βœ… Use .gitignore – Prevent unnecessary files (like logs, dependencies, or config files) from being tracked.


Resources


That’s it! This guide should cover most of what you need in daily Git use. Happy coding! πŸš€

⚠️ **GitHub.com Fallback** ⚠️