-
Initialize a Git Repository:
git init
: Initializes a new Git repository in the current directory.
-
Clone a Repository:
git clone [repository_url]
: Creates a copy of a remote Git repository on your local machine.
-
Status and Information:
git status
: Shows the status of your working directory and staged changes.git log
: Displays the commit history.git branch
: Lists all branches in the repository.git remote -v
: Lists remote repositories associated with your local repository.
-
Adding and Committing Changes:
git add [file(s)]
: Adds changes to the staging area in preparation for a commit.git commit -m "Commit message"
: Commits staged changes with a descriptive message.
-
Branching and Merging:
git branch [branch_name]
: Creates a new branch.git checkout [branch_name]
: Switches to an existing branch.git merge [branch_name]
: Merges changes from one branch into the current branch.git branch -d [branch_name]
: Deletes a branch.
-
Remote Repositories:
git remote add [name] [repository_url]
: Adds a remote repository with a custom name.git push [remote_name] [branch_name]
: Pushes local commits to a remote repository.git pull [remote_name] [branch_name]
: Fetches and merges changes from a remote repository.
-
Undoing Changes:
git reset [file]
: Unstages changes for a specific file.git reset --hard [commit_id]
: Resets the working directory and staging area to a specific commit.
-
Working with Tags:
git tag [tag_name]
: Creates a lightweight tag at the current commit.git tag -a [tag_name] -m "Tag message"
: Creates an annotated tag with a message.git push --tags
: Pushes tags to a remote repository.
-
Git Help:
git --help
: Displays the built-in Git documentation.git [command] --help
: Shows help for a specific Git command (e.g.,git commit --help
).
-
Configuration:
git config --global user.name "Your Name"
: Sets your Git username globally.git config --global user.email "[email protected]"
: Sets your Git email globally.
These are some of the most common Git commands to get you started. Remember to replace [repository_url]
, [branch_name]
, [file]
, [commit_id]
, and [tag_name]
with the appropriate values for your specific use case.
Assignment Title: Git Version Control Basics
Objective: Gain practical experience with Git version control by completing the following tasks.
Instructions:
Task 1: Setup and Configuration
-
Install Git on your computer if it's not already installed. You can download Git from https://git-scm.com/.
-
Open a terminal or command prompt and configure your Git username and email globally using the following commands (replace "Your Name" and "[email protected]" with your actual name and email):
git config --global user.name "Your Name" git config --global user.email [email protected]
-
Use the
git config --list
command to verify your Git configuration. Take a screenshot of the terminal showing the configuration and submit it.
Task 2: Creating a Repository
-
Create a new directory on your computer called "GitAssignment."
-
Navigate to the "GitAssignment" directory using the terminal.
-
Initialize a Git repository in this directory using the
git init
command. -
Create a new text file named "README.md" in this directory.
-
Add some text content (e.g., a brief description of your assignment) to the "README.md" file.
-
Use
git status
to check the status of your repository. Take a screenshot of the terminal showing the status and submit it.
Task 3: Committing Changes
-
Add the "README.md" file to the staging area using the
git add
command. -
Commit the changes to the repository with a meaningful commit message using the
git commit
command. -
Use
git log
to view the commit history. Take a screenshot of the terminal displaying the commit history and submit it.
Task 4: Creating and Switching Branches
-
Create a new branch named "feature-branch" using the
git branch
command. -
Switch to the "feature-branch" using the
git checkout
orgit switch
command. -
Add a new file named "feature.txt" to this branch.
-
Commit the "feature.txt" file to the "feature-branch."
-
Use
git log --oneline --graph --all
to visualize the branch history. Take a screenshot of the terminal showing the branch history and submit it.
Task 5: Merging Branches
-
Switch back to the main branch (usually called "main" or "master") using
git checkout
orgit switch
. -
Merge the changes from the "feature-branch" into the main branch using the
git merge
command. -
Resolve any merge conflicts if they occur.
-
Commit the merge.
-
Use
git log --oneline --graph --all
again to visualize the updated branch history. Take a screenshot of the terminal showing the updated branch history and submit it.
Submission 1:
-
Create a zip file containing all the screenshots and any additional files used for the assignment.
-
Write a brief summary of your experience with Git, mentioning any challenges you faced and how you overcame them.
-
Submit the zip file and summary
Assignment Title: Git Collaboration and Workflow
Objective: Gain hands-on experience with Git collaboration workflows by completing the following tasks.
Instructions:
Task 1: Forking and Cloning
-
Visit a public GitHub repository of your choice (e.g., an open-source project).
-
Fork the repository to create your own copy on GitHub.
-
Clone your forked repository to your local machine using the
git clone
command. -
Verify that the clone was successful by navigating to the cloned repository directory in your terminal.
Task 2: Branching and Collaboration
-
Create a new branch in your local repository. Name it "feature-implementation."
-
Add a new file named "feature.txt" to this branch and write some content in it.
-
Commit the "feature.txt" file to the branch with a meaningful commit message.
-
Push this branch to your forked repository on GitHub using the
git push
command. -
Create a Pull Request (PR) from your "feature-implementation" branch to the original repository's main branch (or an appropriate branch) on GitHub.
-
Add a description to your PR explaining the changes.
Task 3: Review and Merge
-
Ask a friend or classmate to review your Pull Request. If you don't have someone to review it, you can use a secondary GitHub account to simulate a review.
-
Have the reviewer comment on your PR, suggesting improvements or acknowledging its quality.
-
Make any necessary updates to your branch based on the reviewer's feedback.
-
Commit these updates and push them to your branch on GitHub.
-
Request another review from the same person or a different individual.
-
After receiving approval (or simulating it), merge the Pull Request on GitHub.
Task 4: Fetch and Sync
-
In your local repository, switch back to the main branch.
-
Use the
git fetch
command to check for updates from the original repository. -
Create a new branch named "sync-branch" from the main branch.
-
Merge the latest changes from the original repository's main branch into your "sync-branch."
-
Commit the merge, and push the "sync-branch" to your forked repository on GitHub.
Submission 2:
-
Provide the URL to your forked repository on GitHub.
-
Include the link to the Pull Request you created in Task 2.
-
Describe the feedback you received from the reviewer(s) in Task 3 and how you addressed it.
-
Summarize the steps you took to sync your repository with the original repository in Task 4.
Assignment Title: Git Remote and Collaboration
Objective: Gain practical experience with remote repositories and collaboration using Git.
Instructions:
Task 1: Forking a Repository
-
Choose a public GitHub repository | Assignment directory: https://github.com/aeiwz/git_assignment.git.
-
Fork the selected repository to create your own copy on GitHub.
-
Provide the URL to your forked repository on GitHub.
Task 2: Clone and Set Up
-
Clone your forked repository to your local machine using the
git clone
command. -
Configure your local repository to track the original repository as a remote:
git remote add upstream [original_repository_url]
Replace
[original_repository_url]
with the URL of the original repository.
Task 3: Fetching Updates
-
In your local repository, fetch the latest changes from the original repository using:
git fetch upstream
-
Create a new branch in your local repository named "update-branch":
git checkout -b update-branch
-
Merge the changes from the original repository's main branch into your "update-branch":
git merge upstream/main
Task 4: Collaborative Work
-
Make a meaningful code contribution or improvement to the project (e.g., fix a bug, add a feature).
-
Commit your changes with a descriptive commit message.
-
Push your "update-branch" to your forked repository on GitHub:
git push origin update-branch
-
Create a Pull Request (PR) from your "update-branch" to the original repository's main branch on GitHub.
-
Provide the URL to your PR on GitHub.
Task 5: Review and Merge
-
Review at least one open Pull Request in the original repository (submitted by another contributor). Leave a constructive comment or review.
-
If your PR receives comments or review feedback, make necessary updates and respond to comments.
-
After receiving approval or addressing feedback, have your PR merged into the original repository.
Submission 3:
-
Provide the URL to your forked repository on GitHub.
-
Include the URL to your Pull Request in Task 4.
-
Describe the changes you made in your code contribution (Task 4) and your experience with the review process (Task 5).