Git Commands Guide - bounswe/bounswe2025group8 GitHub Wiki
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.
πΉ git init β Creates a new Git repository in your current folder.
Example:
cd my-new-project
git initπΉ git clone <repo-url> β Copies an existing Git repository to your local machine.
Example:
git clone https://github.com/user/project.gitπΉ git status β Shows whatβs changed, whatβs staged, and whatβs untracked.
πΉ git add <file> β Moves a file to the staging area.
Example:
git add index.htmlπΉ 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!
πΉ git log β Displays a list of past commits.
πΉ git branch new-feature β Creates a new branch.
πΉ git checkout new-feature β Moves you to the specified branch.
Shortcut:
git checkout -b new-featureπΉ 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.
πΉ git branch -d new-feature β Deletes a branch after merging.
πΉ git remote add origin <repo-url> β Links your local repository to a remote one.
πΉ git push origin main β Sends your local commits to a remote repo.
πΉ git pull origin main β Fetches and merges updates from the remote repository.
πΉ git fetch origin β Retrieves remote changes without merging them.
πΉ git reset <file> β Removes a file from staging but keeps the changes.
πΉ git checkout -- <file> β Resets a file back to the last committed state.
πΉ git revert <commit> β Creates a new commit that undoes a specific commit.
πΉ git reset --hard <commit> β Resets your repo to a specific commit and deletes all changes after it.
β
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.
Thatβs it! This guide should cover most of what you need in daily Git use. Happy coding! π