- Git Collaboration Guide for Beginners
This guide will help you start collaborating on a shared Git repository, even if you've never used Git before.
First, you need to make a local copy of the repository on your computer:
git clone https://github.com/BigDataRepublic/git-fundamentalsThis creates a new folder with the repository name containing all project files.
cd git-fundamentalsAlways create a new branch for your changes. This keeps your work separate from the main codebase:
git branch my-feature-branch
git checkout my-feature-branchOR use the shortcut command:
git checkout -b my-feature-branchEdit, add, or delete files as needed for your task.
To see which files you've modified:
git statusAdd your modified files to the staging area:
git add filename.txt # Add a specific file
git add foldername/ # Add a folder and its contents
git add . # Add all changesSave your changes with a descriptive message:
git commit -m "Brief description of your changes"Upload your branch to the remote repository:
git push origin my-feature-branchTo see what others have been working on:
git fetchKeep your local main branch updated:
git checkout main
git pull origin mainIncorporate the latest changes from main into your feature branch:
git checkout my-feature-branch
git merge mainIf there are conflicts, Git will notify you and you'll need to resolve them.
Important: This is how your code gets merged into the main codebase!
- Go to the repository on GitHub/GitLab/etc.
- Click on "Pull Requests" or "Merge Requests"
- Click "New Pull Request"
- Select your branch as the source
- Add a title and description explaining your changes
- Submit the pull request
Your team members will review your code, suggest changes if needed, and eventually merge it into the main branch.
Once your changes are integrated in the remote, there is no need to keep your branch (locally and on remote). Simply delete it with:
git checkout main
git branch -D my-feature-branch
git push -d origin my-feature-branchIf you want to undo changes to a file:
git checkout -- filenameTo see the commit history:
git loggit checkout branch-name- Never commit directly to main
- Always create a Pull Request for changes
- Pull regularly to stay updated with others' work
- Communicate with your team about which files you're working on
Happy coding!