Some notes on Git


Create a repository:

git init

Add files to repository to be committed:

git add filename1 filename2  ( add files to stage)

Make files committed

git commit -m "xxx"  (commit files to branch)

Check the result

git status

Version Control:

Compare the difference

git diff filename

Show history

git log


git log --pretty=oneline

Back to one history version

git reset --hard HEAD^   (HEAD - current version, HEAD^ - last version)


git reset --hard commit-id

Discard changes in workplace

git checkout -- filename

Unstage changes

git reset HEAD filename

Undo committed change

git revert HEAD

Delete files from repository

git rm filename

Get the file deleted back

git checkout -- filename


Link local repository with GitHub remote repository

git remote add origin (origin - remote repository)

Push files to remote repository

git push -u origin master (first time)


git push origin master


Create/Switch to a new branch

git checkout -b bname


git switch -c bname

Check current branch

git branch

Merge branch to current branch

git merge bname

Delete branch

git branch -d bname

Hide the current workplace

git stash

Get the latest submission

git pull


git branch --set-upstream-to=origin/dev dev
git pull

Leave a Reply