Learn Git
This is a project to learn git and how to use it.
Getting started with git
Initialized git in current folder
git init
git config --global user.name "Suraj Oliver"
git config --global user.email "suraj.oliver@gmail.com"
Check status of git folder
git status
Add untracked files to git repo and Remove tracked files from git repo to local path
git add -A/--all
git restore filename
Commit marks a savepoint - Stage to commit
git commit -m "second release"
Show all the Logs till date
git log
Git Branches
Creates a new branch
git branch branch_name
Lists all the branches
git branch
Switch to a different branch
git checkout branch_name
Merge a branch with current branch
git merge branch_name
Creating and working with new branch - hello-world-images
git branch hello-world-images
git branch (lists all the branches)
git checkout hello-world-images (switch to this new branch)
git status
git add --all
git status
git commit -m "Added image hello world images"
Working with Multiple Branches
Need to work in emergency fix
git checkout master
git checkout -b emergency-fix (create a new branch and checkout
to that branch)
git status/ git add index.html/ git commit -m "updated
emergency-fix"
git checkout master
git merge emergency-fix
git branch -d emergency-fix
Merge conflicts from hello world
git checkout hello-world-images
git add --all/ git commit -m "added new image"
git checkout master
git merge hello-world-images (Gives merge conflict error)
git status (This will show the merge conflict error)
Working with Github
Maps origin to the github path
git remote add origin
https://github.com/surajoliver/learngithub.git
Push master to origin and make master the default branch
git push --setupstream origin master
Gets all change history for orgin branch
git fetch origin
Other git commands
git log origin/master
git diff origin/master (Find difference between origin/master
and local master)
git merge origin/master (Merge the current branch with the
branch master, on origin)
git pull (Git fetch + Git merge)
git push origin (Push current branch with default remote branch)