Skip to content

Git

Git and GitHub Commands for Collaborators

Initial Setup and Branch Management

Forking the Repository

No direct command; done via the GitHub interface.

Opening with Gitpod

No direct command; performed in the Gitpod interface.

Cloning a Repository

git clone [repository URL]

Creating a New Branch

git checkout -b [new-branch-name]

Staging Changes for Commit

git add [file-name]
or
git add .

Committing Changes

git commit -m "[commit message]"

Pushing Changes to a Remote Repository

git push origin [branch-name]

Opening a Pull Request

No direct command; done via the GitHub interface.

Syncing and Updating Branches

Syncing the Fork with the Upstream Repository

Configuring a Remote for the Upstream Repository:

git remote add upstream https://github.com/[CREATOR-NAME]/[REPO-NAME].git
Fetching from the Upstream Repository:
git fetch upstream
Merging Changes into Your Local Main Branch:
git checkout main
git merge upstream/main
Pushing Changes to Your Local Fork on GitHub:
git push origin main

Updating Your Local Main Branch

git checkout main
git pull origin main

Updating Your Personal Branch in the Fork

git checkout [your-branch-name]
git pull origin main
git push origin [your-branch-name]

Additional Useful Git Commands

Switching Between Branches

git checkout [branch-name]

Merging a Branch into Main (or Master)

git checkout main  # or git checkout master
git merge [branch-name]

Deleting a Branch

Locally:

git branch -d [branch-name]
Remotely:
git push origin --delete [branch-name]

Viewing Branches and Their Status

git branch  # local branches
git branch -a  # all branches

Viewing Commit History

git log

Stashing Changes Temporarily

git stash  # stash changes
git stash apply  # reapply stashed changes

Resolving Merge Conflicts

Manual resolution in the affected files

git add [resolved-file]
git commit

Reverting to a Previous Commit

git revert [commit-hash]

Checking the Status of Your Repository

git status