Git: Difference between revisions

From Dave-Wiki
(Created page with "===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 ===Add New BitBucket Remote to Existing Local Repo=== If you already have an existing...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
=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
===Update Remote Origin===
Useful if you say, migrated a repo from bitbucket -> github.
git remote set-url origin [email protected]:fsudave/repo_name.git
===Check status of the current repo===
===Check status of the current repo===
  git status
git status


===Pull in latest changes from contributors===
===Pull in latest changes from contributors===
  git pull
git pull


===After you make changes to files in your git repo===
===After you make changes to files in your git repo===
  git add .
git add .
  git commit -m "what did you change?"
git commit -m "what did you change?"
  git push -u origin master
git push -u origin master


===Diff between local head and your uncommitted changes===
===Diff between local head and your uncommitted changes===
  git diff <filename>
git diff <filename>


===Discard uncommited changes===
===Discard uncommited changes===
  git checkout -- filename
git checkout -- filename


===Add New BitBucket Remote to Existing Local Repo===
===Discard ALL uncommitted changes===
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 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}
 
==Migrate BitBucket -> GitHub==
 
This is the process to migrate a repo from BitBucket to GitHub:


   git remote add origin git@bitbucket.org:djl09h/repo_name.git
for repo in repo1 repo2 repo3
   git push -f origin master
do
   git clone --mirror https://bitbucket.org/USERNAME/$repo.git
  cd $repo.git
   git push --mirror https://github.com/USERNAME/$repo.git
  cd ..
  rm -rf $repo.git
done

Latest revision as of 15:12, 13 February 2026

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

Update Remote Origin

Useful if you say, migrated a repo from bitbucket -> github.

git remote set-url origin [email protected]:fsudave/repo_name.git

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}

Migrate BitBucket -> GitHub

This is the process to migrate a repo from BitBucket to GitHub:

for repo in repo1 repo2 repo3 do

 git clone --mirror https://bitbucket.org/USERNAME/$repo.git
 cd $repo.git
 git push --mirror https://github.com/USERNAME/$repo.git
 cd ..
 rm -rf $repo.git

done