Git is a collection of commands to edit, track and organize gromramming files. It’s particularily useful in version constroling and joint project. Instead of other tools such as Perforce that only keeps copies on cloud, git also have copy/copy management system in local hardware, in addition, copies are also stored and synchronized online with all progressing versions.
$ git config –global user.name “My Name”
$ git config –global user.email myEmail@example.com
cd to the folder to set git, then type
$ git init
then we got this output: Initialized empty Git repository in /home/user/Desktop/git_exercise/.git/
$ git status to check status
$ git add hello.tx (*.py all python files)
$ git add – A (add all files)
$ git commit -m “intial commit” (commited locally)
Now connect to remote warehouse/on cloudserver (it’s called origin)
$ git remote add origin https://github.com/znaixian/weighting.git
I tried to type above commands, but was told “Git – remote: Repository not found“, so I tried to login github, manually create a repo, then type above commands again, was told the “fatal: remote origin already exists.”. Paradoxical, but anyway, it works so far.
$git push origin master
(push to the cloud)
$ git clone https://github.com/znaixian/weighting.git
$ git pull
(pull from the cloud)
If there is a repo on Github either created directly or you want to clone from, type
Then we need to create a branch to work on sideline, to be eventually pushed/merged into master folder.
git checkout -b experiment (to create a branch named experiment) or $ git branch working-branch
$ git status
on branch master
your branch is up to date with ‘origin/master’
nothing to commit, working tree clean
$ git branch -a ( to view all the branches)
$ git checkout master
$ git checkout working-branch
to switch between branches.
Normally, we do some update on branch, then we need to merge it to the master by $git checkout master, then $git merge branch. type git push to push to github, in between, always can use git status and git log to check.
in linux, use rm -rf folername to delete a folder
ls is same as dir
vi to view the file and then :q to quit
$ git rm python-index-book.mdgit status
$ git commit -m ‘Got rid of stuff’
$ git add
$ git commit -a
$ git push