Skip to content

400 Software Development


Git Basics

Add all files to staging area:

git add .

Commit all files in staging area as a commit:

git commit -m "This is a message"

Push all commits to remote:

git push

Pull all commits from remote:

git pull

Resolving a merge conflict with vimdiff (or another default mergetool):

git mergetool

Vimdiff

:diffget 0 - get local changes for this diff
:diffget 1 - get base changes for this diff
:diffget 2 - get remote changes for this diff
c[ - go to previous change
c] - go to next change

Undoing changes

  • reset is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history.
    • Moves the head back, making changes in those commits unstaged files in the working directory
    • CAUTION: dangerous for already pushed commits
  • restore is about restoring files in the working tree from either the index (staging) or another commit. This command does not update your branch. The command can also be used to restore files in the index from another commit.
    • Remove changes from staging (done by git add) restore --staged
    • Discard changes made to working directory restore
  • revert is about making a new commit that reverts the changes made by other commits.

See Also

See also