0% found this document useful (0 votes)
3 views

Github_Basic

The document provides a comprehensive tutorial on using GitHub, covering essential topics such as creating an account, understanding repositories, cloning, committing changes, pushing and pulling updates, creating branches, merging branches, and managing issues. Each section includes step-by-step instructions and relevant Git commands to facilitate effective collaboration and version control. This guide is designed for beginners to help them navigate and utilize GitHub for their projects.

Uploaded by

Thanh Pham Minh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Github_Basic

The document provides a comprehensive tutorial on using GitHub, covering essential topics such as creating an account, understanding repositories, cloning, committing changes, pushing and pulling updates, creating branches, merging branches, and managing issues. Each section includes step-by-step instructions and relevant Git commands to facilitate effective collaboration and version control. This guide is designed for beginners to help them navigate and utilize GitHub for their projects.

Uploaded by

Thanh Pham Minh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Beginner Print

Creating a GitHub account Tutorial


Creating a GitHub account is the initial step for users to participate in version control and collaborate on
projects. It involves signing up on the GitHub website, providing necessary information such as a
username, email address, and password. Once the account is created, users can configure their profile
and start working with repositories.
Copy
example1
1. Go to https://github.com/join
2. Fill out the signup form with your username, email, and password.
3. Click the 'Create account' button.
4. Verify your email by checking your inbox for a confirmation email from GitHub.
5. Follow the instructions in the email to activate your account.

Understanding repositories Tutorial


A repository, or 'repo', is a central location where all the files related to a particular project are stored
along with their version history. Repositories can be public or private, and they can be hosted on
platforms like GitHub, allowing multiple developers to collaborate, track changes, and manage project
workflows efficiently.
Copy
Creating a new repository on GitHub
1. Go to GitHub.com
2. Click on the '+' icon in the top right corner.
3. Select 'New repository'.
4. Fill in the repository name and description.
5. Choose the visibility (Public/Private).
6. Click 'Create repository'.

Cloning an existing repository


git clone https://github.com/username/repo-name.git

Viewing repository details using Git command line


git remote -v

Checking the status of your repository


git status

Cloning a repository Tutorial


Cloning a repository is the process of creating a local copy of a remote repository hosted on GitHub.
This allows developers to work on the project files directly on their local machines, making it easier to
make changes, experiment, and sync updates back to the remote repository when needed.
Copy
Clone a repository using HTTPS
git clone https://github.com/username/repo.git

Clone a repository using SSH


git clone [email protected]:username/repo.git

Clone with a specific branch


git clone -b branch-name https://github.com/username/repo.git

Committing changes Tutorial


Committing changes in Git is the process of saving your changes to the local repository. Each commit
represents a snapshot of your project at a given point in time, along with a commit message that
describes what changes were made. This is crucial for tracking the history of your project and
collaborating with others, as it allows you to revert to previous states if needed.
Copy
Basic Commit
git add .
git commit -m "Your commit message here"

Committing Specific Files


git add file1.txt file2.txt
git commit -m "Updated file1 and file2"

Amending the Last Commit


git commit --amend -m "Updated previous commit message"

Committing with a Detailed Message


git commit -m "Short summary of changes" -m "Detailed description of what changes were made
and why."

Pushing changes to GitHub Tutorial


Pushing changes to GitHub involves uploading your local repository changes to a remote repository on
GitHub. After committing your changes locally, you can use the git push command to send these
changes to the specified branch of the remote repository. This step is essential for sharing your work
with collaborators and ensuring that the central repository reflects the latest changes.
Copy
Basic Push to Master Branch
git push origin master

Push to a Specific Branch


git push origin feature-branch

Force Push Changes


git push --force origin master

Push All Local Branches


git push --all origin
advertisement
Pulling the latest changes Tutorial
Pulling the latest changes in Git allows you to update your local repository with changes that have been
made in the remote repository. This is an essential practice to ensure that your local copy of the code
reflects the most recent updates made by other collaborators, preventing potential conflicts and
ensuring smooth integration of new features or fixes.
Copy
Basic pull command
git pull origin main

Pulling changes from a specific branch


git pull origin feature-branch

Pulling changes with rebase


git pull --rebase origin main

Pulling all branches


git fetch --all && git pull

Creating a branch Tutorial


Creating a branch in Git allows you to work on features or fixes in isolation from the main codebase. This
is useful for maintaining a clean and stable master branch while you develop new features or experiment
with changes. Each branch can be thought of as a separate line of development, and changes can later
be merged back into the master branch or another branch when they are ready.
Copy
example1
git branch new-feature

example2
git checkout -b new-feature

example3
git switch -b new-feature

Switching between branches Tutorial


Switching between branches in Git allows developers to move between different lines of development in
their projects. This is essential for managing features, bug fixes, and releases, as it enables isolated
workspaces where changes can be made without affecting the main codebase until they are ready to be
merged. Using the git checkout or git switch commands, developers can easily navigate between
branches in their repository.
Copy
Switch to an existing branch
git checkout feature-branch

Create and switch to a new branch


git checkout -b new-feature
Switch using the new command
git switch feature-branch

List all branches and highlight the current branch


git branch

Merging branches Tutorial


Merging branches in Git allows you to integrate changes from one branch into another. This is
commonly used in collaborative environments where multiple developers are working on different
features or bug fixes in their own branches. When you merge a branch, Git combines the individual
changes and creates a new commit in the target branch. If there are no conflicting changes between
the branches, the merge is straightforward, but if there are conflicts, you will need to resolve them
before completing the merge.
Copy
Basic Merge
git checkout main
git merge feature-branch

Merge with Conflict Resolution


git checkout feature-branch
git merge main
# Resolve conflicts in the files manually
git add .
git commit -m 'Resolved merge conflicts'

Merge with Fast-Forward


git checkout main
git merge --ff feature-branch

Squash Merge
git checkout main
git merge --squash feature-branch
git commit -m 'Merged feature-branch squash'

Creating and managing issues Tutorial


Creating and managing issues on GitHub allows developers to effectively track bugs, enhancements,
and tasks within a project. Issues can be assigned to team members, labeled for categorization, and
linked to commits and pull requests, facilitating better communication and project management within a
collaborative environment.
Copy
Creating an Issue via GitHub UI
1. Navigate to the 'Issues' tab in your repository.
2. Click on 'New issue'.
3. Fill in the title and description of the issue.
4. Optionally, assign it to a user or label it.
5. Click 'Submit new issue'.

Creating an Issue via GitHub CLI


# Using GitHub CLI to create an issue:
hub issue create -m "Bug: Fix the login error" -l bug -a @username

Commenting on an Issue
# To comment on an existing issue via GitHub UI:
1. Go to the specific issue page.
2. Scroll to the comments section.
3. Type your comment in the text box.
4. Click 'Comment'.

Closing an Issue
1. To close an issue, navigate to the issue page.
2. Click on Close issue button at the bottom of the page, or comment with Closes
#issue_number in a commit message.

You might also like