Skip to content

Latest commit

 

History

History
225 lines (184 loc) · 5.46 KB

git.md

File metadata and controls

225 lines (184 loc) · 5.46 KB

GIT COMMANDS

INSTALL GIT BASH

  1. Run the command git --version
  2. If there's an error, install Git Bash
  3. Choose default options, but override the branch name with main.
  4. Reload VS Code to apply changes.

INSTALL GITHUB CLI

  1. Run the command gh --version
  2. If there's an error, install GitHub CLI
  3. Choose default options.
  4. Reload VS Code to apply changes.

CONFIGURE USER NAME

  1. Run the command git config user. name.
  2. If it's not correct, run the command git config user. name "myUserName".

CONFIGURE USER EMAIL

  1. Run the command git config user.email.
  2. If it's not correct, run the command git config user.email "[email protected]".

COPY THE REPOSITORY LINK

1. Open GitHub.
2. Open the repository.
3. Click on the green Code button.
4. Copy the HTTPS link.

PULL FROM GITHUB

git init
git remote add origin https://github.com/myRepositoryLink
git pull origin main

DELETE UNUSED FILES

  1. If there are files that VS Code doesn't need (like Glitch files), delete those.

CREATE A NEW REPOSITORY IN GITHUB

  1. Click on the cat icon at the top left.
  2. Click on the green new button at the top left.
  3. Enter the repository name.
  4. Click Create repository.
  5. Do not change the default settings.

PUSH TO GITHUB FOR THE FIRST TIME

gh auth login 
git remote set-url origin https://github.com/myRepositoryLink2 
git add . 
git commit -m "added files" 
git push --set-upstream origin main

PUSH TO GITHUB REGULARLY

git add . 
git commit -m "the changes I made" 
git push

RENAME DEFAULT BRANCH TO MAIN

git branch -M main

SET DEFAULT BRANCH TO MAIN

git config --global init.defaultBranch main

DELETE SOURCE CONTROL

ls -a 
rm -r .git
  • ls-a = List ALL files and folders
  • rm -r.git = removes entire directory/folder (becomes hidden)

COMMAND DESCRIPTIONS

  1. git init
    • Initializes source control
  2. git pull origin main
    • Copies files from the origin
  3. gh auth login
    • Grants authorization to push to your repository
  4. git remote set-url origin
    • Sets the origin
  5. git push --set-upstream origin main
    • Pushes files to GitHub and makes origin and main the default options
  6. git branch
    • Views the branches

CONFIGURE USER NAME

  1. Run the command git init.
  2. Run the command git config user.name.
  3. If it's not correct, run the command git config user.name "myUserName".

PUSH TO GITHUB FOR THE FIRST TIME

  1. gh auth login
  2. git remote set-url origin https://github.com/myRepositoryLink2
  3. git add .
  4. git commit -m "added files"
  5. git push --set-upstream origin main

CONFIGURE USER EMAIL

  1. Run the command git init.
  2. Run the command git config user.email.
  3. If it's not correct, run the command git config user.email "[email protected].

CONFIGURE GLOBAL USER EMAIL (DEFAULT EMAIL)

  1. Run the command git init.
  2. Run the command git config --global user.email.
  3. If it's not correct, run the command git config --global user.email "[email protected].

Force delete repository

PUSH TO GITHUB REGULARLY

git add .
git commit -m "description of changes"
git push

FORCE DELETE REPOSITORY

rm -rf .git

VIEW BRANCHES

git branch

CREATE A BRANCH

git branch branchName

SWITCH TO A BRANCH

git switch branchName

SWITCH TO A BRANCH IN GLITCH

git checkout myBranch

MERGING BRANCH CHANGES

  1. Switch to the branch that will absorb the changes. Example: git switch main
  2. git merge [branchName]

MERGE TEST

INITIALIZE SOURCE CONTROL

  1. git init
  2. touch index.html
  3. git add .
  4. git commit -m "added files"
  5. GITHUB: Create a new repository called merge-test
  6. git remote add origin https://myRepository

PUSH TO A NEW REPOSITORY

  1. git push --set-upstream origin main
  2. git branch myBranch
  3. git switch myBranch
  4. add <p>Hello World!</p> to the index.html file
  5. Save the changes CTRL + S
  6. git add .
  7. git commit -m "updated file
  8. git switch main
  9. Change the history from Auto to All

MERGE THE BRANCH

  1. git merge myBranch
  2. git push
  3. git switch myBranch
  4. Add <p> Amazing World!</p> to index.html file

SETUP FOR REBASE

  1. Save the changes CTRL + S
  2. git add .
  3. git commit -m "updated file"
  4. git switch main
  5. Add the file about.html with touch about.html
  6. git add .
  7. git commit -m "added a file"
  8. git merge myBranch
  9. Approve the merge by closing the merge editor

REBASE THE COMMITS

  1. git rebase myBranch
  2. git push
  3. git switch myBranch
  4. git rebase main

CORRECT A MERGE CONFLICT

  1. Add

    About Page

    to about.html
  2. Save the changes CTRL + S
  3. git add .
  4. git commit -m "added heading"
  5. git switch main
  6. Add

    About Page

    to about.html
  7. Save the changes CTRL + S
  8. git add .
  9. git commit -m "added heading"
  10. git merge myBranch //creates a conflict
  11. Select a resolution.
  12. Save the changes CTRL + S
  13. git add .
  14. git commit -m "merged changes"
  15. git push //fixed a merge conflict

CORRECT A REBASE CONFLICT

  1. git rebase myBranch
  2. Select a resolution
  3. Save the changes CTRL + S
  4. git add .
  5. git rebase --continue
  6. git push //will result in an error
  7. git push --force

RESTORE A SAVE POINT

  1. Select a commit to restore.
  2. Copy its id.
  3. git reset--hard id123456789
  4. git push
  5. git push --force