DEV Community

Cover image for Git Commands
Akash Yadav
Akash Yadav

Posted on

Git Commands

Git Commands: Set Remote and Related Operations

  1. Setting Up a Remote Repository:

    • git remote add origin <remote_repository_url>: Sets up a remote repository with the specified URL as the origin.
  2. Listing Remote Repositories:

    • git remote -v: Lists all remote repositories along with their URLs.
  3. Renaming a Remote Repository:

    • git remote rename <old_name> <new_name>: Renames a remote repository.
  4. Changing the URL of a Remote Repository:

    • git remote set-url origin <new_repository_url>: Changes the URL of the remote repository named 'origin'.
  5. Removing a Remote Repository:

    • git remote remove <remote_name>: Removes the remote repository specified by the name.
  6. Pushing Changes to a Remote Repository:

    • git push <remote_name> <branch_name>: Pushes changes from the local branch to the remote repository.
  7. Pushing Changes to a New Remote Repository:

    • git push -u origin <branch_name>: Pushes changes to a new remote repository and sets it as the default upstream.
  8. Fetching Changes from a Remote Repository:

    • git fetch <remote_name>: Fetches changes from the remote repository without merging them into the local branch.
  9. Pulling Changes from a Remote Repository:

    • git pull <remote_name> <branch_name>: Fetches changes from the remote repository and merges them into the current branch.
  10. Cloning a Remote Repository:

    • git clone <remote_repository_url>: Clones a remote repository to the local machine.
  11. Viewing Remote Details:

    • git remote show <remote_name>: Displays detailed information about the specified remote repository.
  12. Verifying Remote Connectivity:

    • git remote -v: Verifies the connectivity with the remote repository.
  13. Creating a New Branch on the Remote Repository:

    • git push <remote_name> <local_branch_name>:<remote_branch_name>: Creates a new branch on the remote repository.
  14. Deleting a Branch on the Remote Repository:

    • git push <remote_name> --delete <branch_name>: Deletes the specified branch from the remote repository.
  15. Pushing Tags to the Remote Repository:

    • git push <remote_name> --tags: Pushes tags to the remote repository.
  16. Pushing Changes with Force to Remote Repository:

    • git push --force <remote_name> <branch_name>: Forces the push of local changes to the remote repository, potentially overwriting changes.

These commands allow you to manage remote repositories in Git, including setting up, renaming, removing, and interacting with remote repositories for collaboration and version control. Use them to effectively work with remote repositories in your Git projects.

Top comments (0)