GithubHelp home page GithubHelp logo

git's Introduction

Git

Mastering

-------------------------------------Check and remove remote-----------------------------------

Check Remote Origin

To check the current remote origin of your Git repository, use the following command:

bash

git remote -v

Updating Remote Repository URL

If you need to change the remote URL for your Git repository, follow these steps:

  1. View existing remotes:

    git remote -v
  2. Remove the existing remote (replace <remote-name> with the actual remote name, e.g., "origin"):

    git remote remove <remote-name> 
  3. Add a new remote (replace <new-remote-name> and <new-remote-url> with the desired remote name and URL):

    git remote add <new-remote-name> <new-remote-url>
  4. Verify the changes:

    git remote -v

-------------------------------------Simple steps to Upload project-----------------------------------

Basic Steps to Upload Project or Files into GitHub

  1. Initialize a new Git repository:

    git init
  2. Add all files to the staging area:

    git add .
  3. Commit the changes:

    git commit -m "Add existing project files to Git"
  4. Add a remote named 'origin' with the URL of your GitHub repository:

    git remote add origin https://github.com/cameronmcnz/example-website.git

-------------------------------------Change The Branch-----------------------------------

If You Want to Change Branch from 'master' to 'main' or 'main' to 'master'

  1. Check the Current Branch:

    git branch
  2. Switch to Main Branch (if needed):

    git checkout main
  3. Rename the Local Branch (change the local branch):

    git branch -m master main
  4. Push the changes to the remote repository:

    git push -u origin main or git push -u origin master
  5. Push the changes to the 'main' branch on GitHub:

    git push -u origin main

-------------------------------------Undo Recent Commits-----------------------------------

Undoing Recent Commits and Removing Changes

If you want to undo recent commits and remove changes, follow these steps:

Scenario 1: Files not pushed to the remote repository

If the changes have not been pushed to a remote repository, use the following commands:

  1. Undo the Last Commit (Soft Reset), Unstage Changes, and Remove Untracked Files:
    git reset --soft HEAD^
    git reset --mixed
    git clean -fd

Scenario 2: Files already pushed to the remote repository

If the changes have been pushed to a remote repository and you're certain no one else has pulled these changes, use the following commands:

  1. Undo the Last Commit (Soft Reset) and Force Push the Changes:
    git reset --soft HEAD^
    git push -f origin branch-name
    Replace branch-name with the name of your branch. Be cautious with force pushes, as they rewrite the commit history.

Always communicate with your team before making such changes, especially if you're collaborating with others. Additionally, be careful with the git clean command, as it permanently removes untracked files. Use it only if you are sure you want to discard those files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.