This tutorial teaches you GitHub essentials like repositories, branches, commits, and Pull Requests. You’ll create your own Hello World repository and learn GitHub’s Pull Request workflow, a popular way to create and review code
Create GitHub Account
Access GitHub.com and click Sign up.
Choose the free account.
You will receive a verification email at the address provided.
Click the emailed link to complete the verification process.
GitHub Flow is a lightweight, branch-based workflow that supports teams and projects where deployments are made regularly.
Create a branch from the repository.
Create, edit, rename, move, or delete files.
Send a pull request from your branch with your proposed changes to kick off a discussion.
Make changes on your branch as needed. Your pull request will update automatically.
Merge the pull request once the branch is ready to be merged.
Tidy up your branches using the delete button in the pull request or on the branches page.
Working with GitHub
4.1 Create a Repository in GitHub
A repository is usually used to organize a single project. Repositories can contain folders and files, images, videos, spreadsheets, and data sets – anything your project needs.
Steps to create a new repository
1.In the upper right corner, next to your avatar or identicon, click and then select New repository.
2.Name your repository,write a short description,Select Initialize this repository with a README.
3.On Clicking Create repository it will creates the new repository and it is ready for commit the cod
4.2 Adding files to Repository
We can add the files in two ways in GitHub. creating new file
Creating files in Github itself
Upload files from your PC
1.Creating files in Github
• Open the repository in which you want to create a new file
• Click on crete a newfile button on the top
• Provide file name, enter the code you want, give some commit message & say commit new file it will create file in the repository
2.Upload files from your PC
• Open the repository in which you want to upload the files
• Click on Upload Files button on the top
• Add/ Drag files to add them to your repository and commit
On GitHub, saved changes are called commits. Each commit has an associated commit message, which is a description explaining why a particular change was made. Commit messages capture the history of your changes, so other contributors can understand what you’ve done and why.
4.3 Create a Branch in GitHub
Branching is the way to work on different versions of a repository at one time.
By default your repository has one branch named master which is considered to be the definitive branch. We use branches to experiment and make edits before committing them to master.
I want to create a new branch named feature, Here the Steps to do so.
Go to your new repository GitHubDemo.
Click the drop down at the top of the file list that says branch: master.
Type a branch name, feature, into the new branch text box.
Select the blue Create branch box or hit “Enter” on your keyboard.
Here adevelopers, writers, and designers use branches for keeping bug fixes and feature work separate from our master (production) branch. When a change is ready, they merge their branch into master.
4.4 Pull Request in GitHub
Pull Requests are the heart of collaboration on GitHub. When you open a pull request, you’re proposing your changes and requesting that someone review and pull in your contribution and merge them into their branch.
Pull requests show diffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.
Here I made changes in index.html, I added new line in feature/index.html. See how we can create Pull request in github.
Click the Pull Request tab, then from the Pull Request page, click the green New pull request button
Select the branch you made, feature, to compare with master (the original). Look over your changes in the diffs on the Compare page, make sure they’re what you want to submit
When you’re satisfied that these are the changes you want to submit, click the big green Create Pull Request button.
Give your pull request a title and write a brief description of your changes. When you’re done with your message, click Create pull request!
4.5 Merge Pull Request in GitHub
In this final step, it’s time to bring your changes together – merging your feature branch into the master branch.
Click the green Merge pull request button to merge the changes into master.
Click Confirm merge.
Go ahead and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.
5.GitHub with Git Comamd-line Tool
Before you can work with Git on the command line, you will need to set some basic configurations:
Open your git terminal application.
Type git --version to ensure Git is installed. Check git-scm.com to download the latest version.
Type git config --global user.name "USER NAME", replacing USERNAME with your first and last name.
Type git config --global user.email "EMAIL", replacing EMAIL with the email account associated with your GitHub account.
Depending on your operating system, set the core.autocrlf.
• Windows users: Type git config --global core.autocrlf true.
• Mac & Linux users: Type git config --global core.autocrlf input.
- Type git config --list to see your current configurations.
5.1 Clone the Repository Using the Command Line
After you’ve created a repository on the remote, the next step is to clone it to your local environment.
Navigate to the Code tab of the repository on GitHub.com.
Click Clone or download.
Copy the Clone URL provided.
Open your command line/terminal application and cd into the directory where you would like to copy the repository. This can be anywhere in your local file system.
Type git clone URL. Be sure to replace URL with the Clone URL you copied in the previous step. The repository will be cloned into a new directory in this location.
Type cd REPOSITORY-NAME to move into the directory of the repository you just created.
Type git status.
git status is a command you will use often to verify the current state of your repository and the files it contains. Right now, we can see that we are on branch master, everything is up to date with origin/master and our working directory is clean.
5.2 Create Local Branches with Git
Now that you have a local copy of the repository, let’s use the steps of the GitHub Flow to make a change in your project. First we will create a branch:
Create a new branch with a descriptive name: git branch BRANCH-NAME.
Type git status to see that although you created a new branch, you are still checked out to master (as indicated by the in-line response from Git).
Check out to your new branch: git checkout BRANCH-NAME.
Type git status to verify you are now checked out to your new branch.
5.3 Add Local Commits With Git
After you have finished making your changes, it is time to commit them.
Type git status. Remember that git status allows us to see the status of the files on our branch at any given time. Your file is listed under the heading Untracked files.
Type git add FILE-NAME. This adds the file to the staging area and prepares it to become part of the next commit.
Type git status again to see what has changed. Your file is now listed under the heading Changes to be committed.
Type git commit. This tells git to collect all of the files in the staging area and commit them to version control as a single unit of work. Git will open your default text editor where you can enter the commit message.
Type the commit message, save and quit your editor.
o The default text editor associated with git is vi in most cases, which requires that you type :wq to save and quit after entering your commit message.
o Alternatively, you can bypass vi altogether and enter your commit message inline with git commit -m "your message"
- To see the history of commits, type git log.
5.4 Open a Pull Request on GitHub using Git
Now that you have made some local commits, it is time to send your changes to the remote copy of your repository on GitHub.com and create a Pull Request:
Type git push -u origin BRANCH-NAME to push your commits to the remote, and set a tracking branch.
Enter your GitHub username and password, if prompted to do so.
Create a Pull Request on GitHub.
Fill out the body of the Pull Request with information about the changes you’re introducing.
Since this is your repository, you probably don’t have anyone to collaborate with (yet). Go ahead and merge your Pull Request now:
On GitHub.com, navigate to the Pull Request that you just opened.
Scroll down and click the big green Merge Pull Request button.
5.5 Git Pull
After you merge your Pull Request, you will need to update your local copy of the repository:
In your command line, type git checkout master.
Type git pull