Skip to content

Instantly share code, notes, and snippets.

@sajith-rahim
Last active August 20, 2022 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajith-rahim/ca365f2e16fe2aad5c4975937852d7ae to your computer and use it in GitHub Desktop.
Save sajith-rahim/ca365f2e16fe2aad5c4975937852d7ae to your computer and use it in GitHub Desktop.
Old Git Notes.

Version Control System

Types

  1. Local VCS
				> stored in hardisk.
				> no interaction/sharing
				> lost if HDD fails
  1. Centralized VCS
				> has a central remote repo & local copies
				> commits and updates directly to remote.
				> single point of failure
				> eg: SVN
  1. Distributed VCS
				> multiple repos
				> remote server + local clones
				> commit to local and then push and pull to/from remote.
				> eg: Git

### Git * Git stores snapshots of the files (not diff updates). * Git allows for branching ( non-linear development) * Git is secure (SHA-1/MD5) * Git captures change history.

3 Stage Arch.

3 stage arch.


> * HEAD is like an active pointer.

Set Alias for a Command

git config --global alias.br branch

git br is equivalent to git branch now i.e br is an alias for branch command.


## Commands * ``` git init ``` : create a new local repo * ``` git branch ``` : current branch * ``` git diff ``` : show diff (unstaged files) * ``` git diff --stage``` : show diff (staged files)
  • git rm file.md : remove file ( will get staged automatically).

  • git mv f1.md f2.md: move file

  • $ git log --oneline --graph --all : show branches

  • git branch -d branch-name : delete branch.


## Merge 1. ``` git checkout master``` : switch to master 2. ```git merge feature-branch```: merge feature branch onto master branch.

fast forward merge

If master has no commits added since branching, then the head of the master will be fast forwarded.

recursive merge

If master has commits added then a new commit called merge commit will be added to master containing all changes from feature branch


## Rebase 1. ``` git checkout feature``` : switch to feature branch 2. ```git rebase master``` : rebase current branch (feature) onto master.

In rebase: Git

  1. finds the lowest common ancestor of both branches
  2. finds and stores the diffs/commits since the LCA to the head of feature
  3. adds the commits made in master branch (branch you are rebasing onto) to the feature branch
  4. replay the stored commits onto the feature branch

Finally the feature branch will be upto date with clean log containing changes from both.

Now we can do a fast forward merge.

Goal of Merging and Rebasing is same except that rebase provides a cleaner history with linear flow of commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment