Create a repository

From scratch

git init [project_name]

From existing repo

git clone [my_url]

Observe my repository

Files changes in working dir

git status

Changes made to track files

git diff

History of changes

git log

Show a commit

git show [ID]: [file]

All local branches

git branch

Update

Pull latest changes (fetch + merge)

git pull

Fetch latest changes (does not merge)

git fetch

Publish

Stages file

git add [file]

Commit all local changes

git commit -m [comment] -a

Push changes to origin

git push

Revert

Return to the last commited state

git revert --hard

Revert to specific commit

git revert [ID]

Fix the last commit (after editing the broken file)

git commit --amend

Manage branches

Switch to a branch

git checkout [branch_name]

Create a branch

git branch [branch_name]

Delete a branch

git branch -d [branch_name]

Resolve merge conflicts

View merge conflicts

git diff

Discard a conflicting patch

git reset --hard

After resolving conflict, merge with

git add [conflicting_file]

GIT Workflow

git rebase --continue

Leave a Comment

Your email address will not be published. Required fields are marked *