Git: Difference between revisions

From Dave-Wiki
No edit summary
 
Line 32: Line 32:
===Discard ALL uncommitted changes===
===Discard ALL uncommitted changes===
  git reset --hard HEAD
  git reset --hard HEAD
==gitignore==
===Remove files from repo after adding to .gitignore===
Sometimes you commit a repo but forgot to add certain files to your .gitignore. If you've already committed, you can remove those file you want to ignore from your repo, but keep the local copy of them. Here's how:
git rm --cached -r {file}

Latest revision as of 19:51, 6 March 2025

Summary

Git is a distributed version control system that helps developers track changes in their code, collaborate efficiently, and manage different versions of a project. It allows users to create branches for new features or fixes, merge changes, and revert to previous versions if needed. Git operates locally, but it can sync with remote repositories like GitHub, GitLab, or Bitbucket for team collaboration. With features like commits, pull requests, and conflict resolution, Git provides a flexible and powerful way to manage source code in software development.

General

Common Tasks

Add New BitBucket Remote to Existing Local Repo

If you already have an existing local repo but would like to get it on BitBucket, you may need to do this after creating the BitBucket repo:

git remote add origin [email protected]:djl09h/repo_name.git
git push --set-upstream origin master

Check status of the current repo

git status

Pull in latest changes from contributors

git pull

After you make changes to files in your git repo

git add .
git commit -m "what did you change?"
git push -u origin master

Diff between local head and your uncommitted changes

git diff <filename>

Discard uncommited changes

git checkout -- filename

Discard ALL uncommitted changes

git reset --hard HEAD

gitignore

Remove files from repo after adding to .gitignore

Sometimes you commit a repo but forgot to add certain files to your .gitignore. If you've already committed, you can remove those file you want to ignore from your repo, but keep the local copy of them. Here's how:

git rm --cached -r {file}