git init
Initialize an empty Git repository.
git status
Displays the state of your working directory and staging area.
git add readme.txt
Stages readme.txt
for the next commit.
git add .
Stages all changes (new, modified, or deleted files).
git commit -m "Create readme file"
Commits staged changes with a descriptive message.
git config --global core.editor notepad
Configures Notepad as the editor when no message is provided with git commit
.
git diff readme.txt
Shows changes between the working directory and the last commit for readme.txt
.
git diff
Shows changes between working directory and staging area.
git diff --staged
Displays differences between the staging area and the latest commit.
git log
Displays the commit history.
git log --pretty=oneline
Displays each commit in a single line.
git checkout b346471
Checks out a commit using its unique hash.
git checkout main
Switches to the main branch.
git -v
Displays the current Git version.
git config -l
Lists all configurations.
git config --global user.name "Thomas Claudius Huber"
git config --global user.email "[email protected]"
Sets up the global username and email for commits.
git config -l --show-origin
Shows where configurations are stored.
git branch
Lists all local branches.
git branch feature/AddTwitterHandle
Creates a new branch called feature/AddTwitterHandle
.
git checkout feature/AddTwitterHandle
Switches to the new branch.
git merge feature/AddTwitterHandle
Merges the feature/AddTwitterHandle
branch into main
.
git log --pretty=oneline --graph
Displays the commit history as a graph.
git remote add origin https://repositoryURL
Adds a remote repository under the name origin
.
git push -u origin main
Pushes changes to the main
branch and sets it as upstream.
git clone https://repositoryURL
Clones a remote repository to your local machine.
git fetch
Downloads changes from the remote without merging them.
Now you know the basics of Git, including how to initialize a repository, stage changes, commit, push, fetch, and branch!
# Summary of Git Commands for Pull Request Workflow
This document provides a step-by-step summary of the Git commands used for forking, making changes, and creating a pull request (PR) in a collaborative workflow.
Clone the forked repository to your local machine.
git clone https://github.com/your-username/forked-repo.git
cd forked-repo
Edit the files as needed, then stage and commit your changes.
git add filename.ext
git commit -m "Added new function in filename.ext"
Add the original repository as an upstream remote to keep your fork updated.
git remote add upstream https://github.com/friend-username/original-repo.git
Fetch any updates from your friend's original repository.
git fetch upstream
Merge the fetched changes into your local branch to ensure it’s up-to-date.
git merge upstream/main
Push your local changes to your forked repository on GitHub.
git push origin main
- Go to your forked repository on GitHub.
- Click on "Compare & pull request".
- Review the changes and submit the pull request (PR).
When creating a pull request, use a descriptive title like:
Add new feature for calculating user scores
This ensures clarity about the changes you made.