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.
1
2
3
4
5
6
7
8
9
10
11
12
13# config user
git config --global user.name "Jimmy Kuo"
git config --global user.email "jimmy@gogojimmy.net"
# set up git core editor
git config --global core.editor "code --wait"
# checkout git config file
cat ~/.gitconfig
# setup alias
git config --global alias.st status
#Apply no white space warning
git config --global apply.whitespace nowarn
# Add UI Color
git config --global color.ui trueRemote Git Commands
1
2
3
4
5
6
7
8# Init Project
git init
# Clone project
git clone <remote url>
# Push your repo
git push or git push origin master
# Pull repo update your current repo with remote repo
git pullBasic Git Commands
1
2
3
4
5
6
7
8# check current status
git status
# add certain file
git add <certain file>
# add all files
git add.
# Commit with a message
git 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.
1
2
3
4
5
6
7
8
9
10
11
12# create new branch named cat
git branch cat
# checkout to cat branch
git checkout cat
# after you finished with branch, you checkout to master first and merge
git merge
# you can rebase with master and your commits with branch will be put at the end of master branch
git rebase master
# check out the diff between current branch and master branch
git diff
# delete branch name
git 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”