Mastering
-------------------------------------Check and remove remote-----------------------------------
To check the current remote origin of your Git repository, use the following command:
git remote -v
If you need to change the remote URL for your Git repository, follow these steps:
-
View existing remotes:
git remote -v
-
Remove the existing remote (replace
<remote-name>
with the actual remote name, e.g., "origin"):git remote remove <remote-name>
-
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>
-
Verify the changes:
git remote -v
-------------------------------------Simple steps to Upload project-----------------------------------
-
Initialize a new Git repository:
git init
-
Add all files to the staging area:
git add .
-
Commit the changes:
git commit -m "Add existing project files to Git"
-
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-----------------------------------
-
Check the Current Branch:
git branch
-
Switch to Main Branch (if needed):
git checkout main
-
Rename the Local Branch (change the local branch):
git branch -m master main
-
Push the changes to the remote repository:
git push -u origin main or git push -u origin master
-
Push the changes to the 'main' branch on GitHub:
git push -u origin main
-------------------------------------Undo Recent Commits-----------------------------------
If you want to undo recent commits and remove changes, follow these steps:
If the changes have not been pushed to a remote repository, use the following commands:
- Undo the Last Commit (Soft Reset), Unstage Changes, and Remove Untracked Files:
git reset --soft HEAD^ git reset --mixed git clean -fd
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:
- Undo the Last Commit (Soft Reset) and Force Push the Changes:
Replace
git reset --soft HEAD^ git push -f origin branch-name
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.