Local Repository
A local repository is hosted on a local machine for an individual user.
Some essential Git commands for working with a local repository:
1. Set Git configuration values like username and email on a global level:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
2. Initialize a new local repository:
git init
3. Add files or directories to the staging area:
git add <file1/directory1> <file2/directory2>
4. Remove files or directories from a Git repository:
# remove files
git rm <file1> <file2>
# remove directories
git rm -rf <directory1> <directory2>
5. View the state of the working directory and the staging area:
git status
6. Commit changes to the local repository:
git commit -m "Commit message"
7. View the commit history:
git log
8. Create a new branch:
git branch <branch-name>
9. Switch to a different branch:
git checkout <branch-name>
Remote Repository
A remote repository is hosted on a remote (this could be on the internet or an off-site server; it could even be the same machine in a different path) and is shared among multiple team members.
Some essential Git commands for working with a remote repository:
1. Clone a remote repository:
git clone <remote-url>
2. Add a remote repository:
git remote add <remote-name> <remote-url>
3. Push local commits to a remote repository:
git push <remote-name> <branch-name>
4. Pull the latest changes from a remote repository:
git pull <remote-name> <branch-name>
5. Fetch the latest changes from a remote repository:
git fetch <remote-name>
6. Create a new branch in the remote repository:
git push <remote-name> <local-branch-name>:<remote-branch-name>