Background
Git is a version control system. It tracks the changes you make. Every team uses some kind of versioning tool. One of the biggest features of git is branches. It’s the most popular version constrol system out there and many companies uses it.
Before I start working I actually don’t use git or only use the basic commands. Now I started working I need to use git to upload my work and how to use git to enhance my work experience. Here are some basic commands to get started.
Basic Commands
Basic config.
12345678910111213# config usergit config --global user.name "Jimmy Kuo"git config --global user.email "jimmy@gogojimmy.net"# set up git core editorgit config --global core.editor "code --wait"# checkout git config filecat ~/.gitconfig# setup aliasgit config --global alias.st status#Apply no white space warninggit config --global apply.whitespace nowarn# Add UI Colorgit config --global color.ui trueRemote Git Commands
12345678# Init Projectgit init# Clone projectgit clone <remote url># Push your repogit push or git push origin master# Pull repo update your current repo with remote repogit pullBasic Git Commands
12345678# check current statusgit status# add certain filegit add <certain file># add all filesgit add.# Commit with a messagegit commit -m "Git init"Git Branch.
Branch is one of the biggest features in git. It’s cheap. Basically you create a branch when you want a new feature, fix bug, or try something new.
123456789101112# create new branch named catgit branch cat# checkout to cat branchgit checkout cat# after you finished with branch, you checkout to master first and mergegit merge# you can rebase with master and your commits with branch will be put at the end of master branchgit rebase master# check out the diff between current branch and master branchgit diff# delete branch namegit branch -d "branch name"Merge Conflict
- When merge conflict occurs, git should open your default editor where you can resolve conflict. (*don’t forget to delete <<<, ===, >>>)
- Use git add to stage finished file.(continue until all conflicts are complete)
- git commit -m “merge complete”