Motivation:
You want to use Git to version your files or share your files with other people.
Solution:
- Register a GitHub or a GitLab account.
- Create a GitHub repository or a GitLab project.
- Download and install a Git client.
- Generate a personal access token.
- Pull (checkout) a remote repository (e.g. https://github.com/huybien/asp.net-core.git) to an empty local folder (e.g. C:\Users\admin\Downloads\code).
git initgit config user.email "info@huybien.com"git config user.emailgit config user.name "Huy Bien"git config user.namegit config credential.helper ""cd C:\Users\admin\Downloads\codegit remote add origin -f https://github.com/huybien/asp.net-core.gitgit pull origin main/ * or * /git pull origin master/ * Enter username and token. */git init git config user.email "info@huybien.com" git config user.email git config user.name "Huy Bien" git config user.name git config credential.helper "" cd C:\Users\admin\Downloads\code git remote add origin -f https://github.com/huybien/asp.net-core.git git pull origin main / * or * / git pull origin master / * Enter username and token. */
git init git config user.email "info@huybien.com" git config user.email git config user.name "Huy Bien" git config user.name git config credential.helper "" cd C:\Users\admin\Downloads\code git remote add origin -f https://github.com/huybien/asp.net-core.git git pull origin main / * or * / git pull origin master / * Enter username and token. */
- Pull (checkout) a remote repository (e.g. https://github.com/huybien/asp.net-core.git) to a local folder that contains existing code (e.g. C:\Users\admin\Downloads\code).
cd C:\Users\admin\Downloads\codegit init --initial-branch=maingit config user.email "info@huybien.com"git config user.emailgit config user.name "Huy Bien"git config user.namegit config credential.helper ""git remote add origin https://github.com/huybien/asp.net-core.gitgit fetch --all/ * Enter username and token. */git add *.*git commit -m "new files added"git push -u origin main/ * Enter username and token. */cd C:\Users\admin\Downloads\code git init --initial-branch=main git config user.email "info@huybien.com" git config user.email git config user.name "Huy Bien" git config user.name git config credential.helper "" git remote add origin https://github.com/huybien/asp.net-core.git git fetch --all / * Enter username and token. */ git add *.* git commit -m "new files added" git push -u origin main / * Enter username and token. */
cd C:\Users\admin\Downloads\code git init --initial-branch=main git config user.email "info@huybien.com" git config user.email git config user.name "Huy Bien" git config user.name git config credential.helper "" git remote add origin https://github.com/huybien/asp.net-core.git git fetch --all / * Enter username and token. */ git add *.* git commit -m "new files added" git push -u origin main / * Enter username and token. */
- Push local files to a remote empty repository.
git initgit config user.email "info@huybien.com"git config user.emailgit config user.name "Huy Bien"git config user.namegit config credential.helper ""git add *.*git commit -m "first commit"git branch -M maingit remote add origin https://github.com/huybien/asp.net-core.gitgit push -u origin maingit init git config user.email "info@huybien.com" git config user.email git config user.name "Huy Bien" git config user.name git config credential.helper "" git add *.* git commit -m "first commit" git branch -M main git remote add origin https://github.com/huybien/asp.net-core.git git push -u origin main
git init git config user.email "info@huybien.com" git config user.email git config user.name "Huy Bien" git config user.name git config credential.helper "" git add *.* git commit -m "first commit" git branch -M main git remote add origin https://github.com/huybien/asp.net-core.git git push -u origin main
- Push changes to a remote repository.
git config user.email "info@huybien.com"git config user.emailgit add *.*git commit -m "CP form"git branch -M maingit push -u origin maingit config user.email "info@huybien.com" git config user.email git add *.* git commit -m "CP form" git branch -M main git push -u origin main
git config user.email "info@huybien.com" git config user.email git add *.* git commit -m "CP form" git branch -M main git push -u origin main
- Update (fetch and merge) a local repository.
git pull origin main/* or */git branch --set-upstream-to=origin/main maingit pullgit pull origin main /* or */ git branch --set-upstream-to=origin/main main git pull
git pull origin main /* or */ git branch --set-upstream-to=origin/main main git pull
- Force updating (fetch and overwrite) the current repository.
git fetch --allgit reset --hard origin/maingit clean -fd git pullgit fetch --all git reset --hard origin/main git clean -fd git pull
git fetch --all git reset --hard origin/main git clean -fd git pull
- Force updating (fetch and overwrite) a local repository (e.g. C:\Users\admin\Downloads\code).
git -C C:\Users\admin\Downloads\code fetch --allgit -C C:\Users\admin\Downloads\code reset --hard origin/maingit -C C:\Users\admin\Downloads\code clean -fdgit -C C:\Users\admin\Downloads\code pullgit -C C:\Users\admin\Downloads\code fetch --all git -C C:\Users\admin\Downloads\code reset --hard origin/main git -C C:\Users\admin\Downloads\code clean -fd git -C C:\Users\admin\Downloads\code pull
git -C C:\Users\admin\Downloads\code fetch --all git -C C:\Users\admin\Downloads\code reset --hard origin/main git -C C:\Users\admin\Downloads\code clean -fd git -C C:\Users\admin\Downloads\code pull
- Reset (Revert) a local repository to a previous version.
cd C:\Users\admin\Downloads\codegit log --onelinegit reset --hard 4355842// where 4355842 is a version id.cd C:\Users\admin\Downloads\code git log --oneline git reset --hard 4355842 // where 4355842 is a version id.
cd C:\Users\admin\Downloads\code git log --oneline git reset --hard 4355842 // where 4355842 is a version id.
- Remove all cached files.
git rm -r --cached .git rm -r --cached .
git rm -r --cached .
- Display remote URL.
git config --get remote.origin.urlgit config --get remote.origin.url
git config --get remote.origin.url
(Visited 92 times, 1 visits today)