2. www.edureka.co/git-github
What will you learn today?
Creating GitHub repository
Pushing code to remote GitHub repository
Unstaging files
Using alias and gitignore file
Creating new branches and merging them back to master branch
5. www.edureka.co/git-github
Creating a remote GitHub Repository
To push the committed changes, you need to create a repository on GitHub. To create a
GitHub repository go to https://github.com/ and create a new repository, by clicking on New
repository link
7. www.edureka.co/git-github
Pushing to GitHub Repository
Once GitHub repository is created copy the repository link and push the code as shown below
Note that master is the default branch which is created automatically when we create a GitHub repository
8. www.edureka.co/git-github
Changes on GitHub repository
After pushing changes to GitHub repository, all the committed code can be seen on GitHub. Its
always a good idea to put a README file in all the GitHub repo which explains about repository
13. www.edureka.co/git-github
Creating a remote handle
Previously we pushed the changes to remote repository using the URL of the repository. Rather than
typing the URL each time or copying and pasting the URL, we can create a short handle for that as shown
below
Creating a remote handle
Pushing changes to GitHub repository
Note that master is the default branch which is created automatically when we create a GitHub repository
15. www.edureka.co/git-github
Staging and Committing in one command
We can stage and commit changes in one command by combining git add and git commit, as shown below
Note that we have used && operator to combine both add and commit command
19. www.edureka.co/git-github
Creating Alias
Staging and committing is very frequent operation while working with Git, its always a good option
to create a short alias for long Git commands that you have to type frequently
Above we have created alias add-commit for add and commit git commands
20. www.edureka.co/git-github
Removing some files from Commit
Its always a good practice to commit only those files to GitHub repository that are required. So if you are
having a Java project you should remove .class files and any other file that have sensitive information e.g.
username/password etc.
24. www.edureka.co/git-github
Unstaging a file
Consider the scenario where you have two files meetup-session.py and exercise.py
You accidentally put both the files in staging area but you only want to commit meetup-session.py
Problem :
Solution :
We can unstage the exercise.py by using git rm --cached <file>
29. www.edureka.co/git-github
Why Branching ?
You will copy courses.html file and rename it to something else (in this case courses2.html).
Once you are satisfied with your changes in courses2.html, you will delete courses.html file and
rename courses2.html to courses.html. This tedious workflow can easily be solved by Git
31. www.edureka.co/git-github
Committing all the changes
After committing all the changes
Now you want to add new feature to the project without messing with the current working code.
Lets see how to achieve this efficiently with Git branching
32. www.edureka.co/git-github
Creating a new branch and switching to it
Creating new branch newFeature from master branch
Switching to new branch newFeature from master branch
33. www.edureka.co/git-github
Making changes in new branch
courses.html
Just for demo purpose lets add a title tag and h1 header tag to courses.html, while we are
working in newFeature branch
35. www.edureka.co/git-github
Unstaged changes in new branch
Lets add a new file about.html while we are on newFeature branch
So we have modified courses.html and added a new file about.html while we are working on
newFeature branch
37. www.edureka.co/git-github
Magic of Branches
When we switch to master branch, about.html will not be present as shown below, because those
changes were made in newFeature branch and not in master branch.
To combine those changes in master branch we will have to merge newFeature branch in master branch
38. www.edureka.co/git-github
Merging Branches
To merge newFeature branch into master, first checkout to master branch and use the command
git merge newFeature, as shown below
After merging, about.html and any other changes made in newFeature branch will be reflected in
master branch as shown below
39. www.edureka.co/git-github
Survey
Your feedback is vital for us, be it a compliment, a suggestion or a complaint. It helps us to
make your experience better!
Please spare few minutes to take the survey after the webinar.