Complete Git and Github Masterclass
- 1. Git material
- 2. Rebase with a pull
- 3. Squash commits together
- 4. Aborting a squash
- 5. git log
- 6. Complete Git and Github Masterclass
- 7. Git Fundamentals
Git material
Pro Git
LearnGitBranching
tryGit
Rebase with a pull
git pull --rebase origin master
It essentially puts the new commits in the master of the remote in your hisotry, and then superimpose your commits on them.
Squash commits together
git rebase -i HEAD~2
Squash the last two commits.
The HEAD~2 refers to the last two commits in the current branch, and the -i option stands for interactive.
pick and squash
Pick the old commit and squash the latest commit.
Aborting a squash
git rebase --abort
get back to the pre-squash state
git log
git log --oneline --decorate --graph --all
Complete Git and Github Masterclass
How Git works - 3 main states of artifact
Modified: Here, the artifact goes through chaneg made by the user
Staged: Here, the user/developer adds the artifact to Git index or staging area
Committed: Here, the artifact gets safely stored in Gt database.
git add: files moved from modified state to staged state
git commit: files moved from staged state to committed state
natural state progression is from modified-> staged-> committed
express commit: git commit -am “commiting readme.md”
3 sections of a Git project
Working directory: this is the root directory of your Git project
Staging area: Also called index, this is where all related changes are build up
Commit area: this is where all artifacts are stacked safely in Git Database
3 ways of setting up Git repository
From scratch: we will create a repository from absolutely blank state
Existing project: here we will convert an existing unversioned project to a Git repository
By Copying: we will copy an existing Git repository from Github
Git Help system
git help -a
and git help -g
list available subcommands and some concept guides
What is Fork and how to do it
What it means: Creating a project from another existing project
Encouragement: encourages project advancement & collaboration
Contribution: encourages outside contribution
Updates: Forks can updated
Command git status
: tells us the status of the working directory and staging area
Command git log
: displays committed snapshots or commit history
Git branching
Show branch: git branch
Create a new branch: git branch demobranch
Switch to the new branch: git checkout demobranch
checkout git branches: git checkout; git checkout -b
list git branches: git branch; git branch -a
rename a git branch: git branch -m
delete a git branch: git branch -d; git branch -D
Undoing changes in a Git repository
Checking out commits in a Git repository
vim robot.txt
Express git add and commit command:
1 | git commit -am "1st commit - robot.txt" |
Create a new branch:
git checkout -b newbranch
Switch branch:
1 | git checkout master |
Checking out files in a Git repository
1 | git log --oneline |
Reverting changes in a Git repository
1 | git add . |
Resetting Git repository
git reset --hard
resets the staging area and working directory to match the most recent commit.
git reset --hard hash_vaule
moves the current branch id backward to commit id we are using and reset the both the staging area and work dir to match, this destroy not the current change and both the commit id as well.
Cleaning Git repository
1 | git clean -n |
1 | # #### ###### ###### ## ## ######## |
If github ask for username and password:
git remote set-url origin git@github.com:szhouchoice/EffectiveDevOpsTerraform.git
Merge branch into master
1 | # ...develop some code... |
1 | git add foobar/foobar.php |
Git Fundamentals
Initalizing a Repo and Adding Files (commands)
1 | git init |
Undoing/updating things
1 | git commit --amend |
Getting help
1 | git <command> -h |
Git config file
1 | Scope |
Git Status
1 | Command: git status |
Git special references: Head and Index
1 | Head |
Showing differences
1 | command: git diff |
History
1 | command: git log |
git useful command
1 | git clone git@bitbucket.org:foobar/pagerduty.git --config core.autocrlf=input |