Wednesday, December 13, 2017

GitLab Commands


After create a new repository on gitlab, it usually gives below command line instructions.

Git global setup
git config --global user.name "Jim Zhao"
git config --global user.email "jim@example.com"

Create a new repository
git clone https://gitlab.com/jimzhao/test.git
cd test
touch README.md
git add README.md
git commit -m "add file"
git push -u origin master

Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/jimzhao/test.git
git commit -m "init message"
git push -u origin master

Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/jimzhao/test.git
git push -u origin --all
git push -u origin --tags


How to check changes on remote origin git repository?


There are couple of ways and lots of discussion regarding check changes on remote git repository.

git remote update - bring your remote refs up to date
git status - tell you whether the branch you are tracking is ahead, behind or has diverged

git show-branch *master - show commits in all of the branches whose names end in master (eg master and origin/master)

git pull origin master - bring my local up to date

git fetch origin - update the remote branch in your repository to point to the latest version
git diff origin/master - diff local against the remote
git merge origin/master - accept the remote changes

git remote show origin - Show synthetic view of what's going on remote "origin" repository

Tuesday, December 12, 2017

Git 101


git add - Add file contents to the index.
git branch - List, create, or delete branches
git bisect - Find by binary search the change that introduced a bug
git checkout - Checkout a branch or paths to the working tree
git clone - Clone a repository into a new directory
git commit - save staged changes to local repository
git diff - Show changes between commits, commit and working tree, etc
git fetch - download objects and refs from another repository
git grep - Print lines matching a pattern
git init - reate an empty Git repository or reinitialize an existing one
git log - show commit logs
git merge - Join two or more development histories together
git mv - Move or rename a file, a directory, or a symlink
git pull - Fetch from and merge with another repository or a local branch
git push - Update remote refs along with associated objects
git rebase - Rebasing is the rewinding of existing commits on a branch with the intent of moving the branch start point forward, then replaying the rewound commits.
git reset - Reset current HEAD to the specified state
git rm - Remove files from the working tree and from the index
git show - Show various types of objects
git status - Show the working tree status
git tag - create tagging.

git help xxx - to show help info

Wednesday, December 6, 2017

Yarn 101

Yarn is a new package management tool from Facebook, it is designed to solve daily development issues using NPM client. There are lots of posts to explain the advantages of Yarn. And the beauty of this tool is: Yarn is compatible with NPM and bower.

Here are some frequent commands for Yarn usage:

yarn init

yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

yarn remove [package]

yarn install

Installing all dependencies: yarn or yarn install
Installing one and only one version of a package: yarn install --flat
Forcing a re-download of all packages: yarn install --force
Installing only production dependencies: yarn install --production

Yarn reads package.json, generate yarn.lock file. These two key files are expected to check into version control system to share across team, so that each team member will get the same dependency list and install the same packages on different machines.

Developer can use npm and yarn at the same time, but we strongly recommend to use yarn to manage the packages due to the pitfalls from npm. The commands are easy to remember too.

yarn add -> npm install -save
yarn upgrade -> npm update (up, upgrade)
yarn remove -> npm uninstall
yarn install -> npm install