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

How To Used Git and GitHub

Git allows users to track changes to files and collaborate on code projects. It can be initialized on a local repository and then connected to GitHub for remote collaboration. Files can be staged, committed locally with messages, and then pushed to GitHub after setting a remote. Others can clone the GitHub repository to contribute or pull recent changes. Branching enables parallel development and pull requests allow review before code is merged.

Uploaded by

phonefire61
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

How To Used Git and GitHub

Git allows users to track changes to files and collaborate on code projects. It can be initialized on a local repository and then connected to GitHub for remote collaboration. Files can be staged, committed locally with messages, and then pushed to GitHub after setting a remote. Others can clone the GitHub repository to contribute or pull recent changes. Branching enables parallel development and pull requests allow review before code is merged.

Uploaded by

phonefire61
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Git Basics:

Configuring Git:

After installation, open a terminal or command prompt and set your name and email address:

git config --global user.name "Your Name"

git config --global user.email "[email protected]"

Creating a New Repository:

To start using Git, you'll need to initialize a repository. Navigate to the directory where you want to
create your project and run:

git init

Adding Files:

Use git add to stage files for the next commit. For example:

git add file.txt

Committing Changes:

Once you've staged the changes, you can commit them:

git commit -m "Your commit message"

Checking Status:

To see the status of your repository, use:

git status

Viewing Commit History:

You can view the commit history with:

git log

GitHub Basics:
Creating a New Repository on GitHub:

Click on the '+' sign in the top right corner and select "New repository". Follow the instructions to
create a new repository.

Pushing to GitHub:

To push your local repository to GitHub, you'll need to add a remote. Replace username and
reponame with your GitHub username and repository name:

git remote add origin https://github.com/username/reponame.git

Then, push your code to GitHub:

git push -u origin master


Cloning a Repository:

To work on an existing repository from GitHub, you'll need to clone it:

git clone https://github.com/username/reponame.git

Pulling Changes:

To get the latest changes from the remote repository, use:

git pull origin master

Branching:

Create a new branch for development using:

git branch new-branch

Switch to the new branch:

git checkout new-branch

Merging Branches:

After making changes in a branch, you can merge it back into the main branch (usually master):

git checkout master

git merge new-branch

Pull Requests:

When working with others, it's common to make changes on a separate branch and then create a
pull request on GitHub. This allows others to review your changes before merging them into the
main branch.

You might also like