Git Commands for Team Work

Create a repo without checking "add readme.me."

Use the following commands:

git init

Add Collaborators to Your Repository

Go to the settings and on the left-hand side, click on "Collaborators." From there, you can easily add your team members by username or email.

Accepting Collaboration Requests

After sending a collaboration request, your team member has to accept this request by clicking on the email or just clicking on the profile picture on GitHub and going to "Your Organization" to join the team.

Error & Solutions

If you encounter the error: "remote origin already exists," you can check the existing remotes with git remote -v. To change or remove the existing link, use git remote remove origin, and then add the new remote with git remote add origin <link> followed by git push -u origin main.

By joining the team, you can directly push your work without the owner's permission, but you should create another branch for your future benefits.

Notes:

  1. Please create a separate folder for your project.
  2. Also, make a text file or any file as needed.
  3. Make your repo from the GitHub website and do not check/tick "README.MD" during the initial setup.

Setup on CMD/GitBash

Configure your global Git settings:

git config --global user.name "YourUserName"
git config --global user.email "your@email.com"

Important Commands

  1. git init: Initialize a Git repository.
  2. git status: Check the status of your repository.
  3. git add .: Stage all changes for commit.
  4. git status: Check the status after staging.
  5. git commit -m "First Commit": Commit your changes with a message.
  6. git branch -M main (if you encounter an error): Rename the default branch to "main."

Uploading Commands

git remote add origin <YourRepoLink>: Add the remote repository where you want to push and pull changes.
git push -u origin main: Push your changes to the main branch on the remote repository.

Branches

  1. git branch: Show all branches.
  2. git branch <BranchName>: Create a new branch.
  3. git checkout <BranchName>: Switch to a specific branch.

Merge

  1. git branch --merged: List branches that have been merged into the current branch.
  2. git merge <BranchName>: Merge changes from the specified branch into the current branch.
  3. git push origin main: Push changes from the current branch to the main branch on the remote repository.