0% found this document useful (0 votes)
55 views

Git Commands

This document provides instructions for various Git commands: 1. It describes how to configure Git to use different text editors like Notepad or Visual Studio Code. 2. It lists common Git commands like git init, git add, git commit, git status, git log to create repositories, track changes, and view the commit history. 3. It provides instructions for removing and recreating a Git repository, viewing diffs, resetting to previous commits, and checking out specific files or branches.

Uploaded by

Rio Pramana
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Git Commands

This document provides instructions for various Git commands: 1. It describes how to configure Git to use different text editors like Notepad or Visual Studio Code. 2. It lists common Git commands like git init, git add, git commit, git status, git log to create repositories, track changes, and view the commit history. 3. It provides instructions for removing and recreating a Git repository, viewing diffs, resetting to previous commits, and checking out specific files or branches.

Uploaded by

Rio Pramana
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

exit vim = ctrl + w + q

# Configure Git to use Notepad


git config --global core.editor notepad

# Configure Git to use Visual Studio Code


git config --global core.editor "code --wait"

git init -> create empty Git repo (create space to store the snapshots)

git add {filename} -> take a snapshot/"photo" of the file

git add . -> add all files in the dir

git status -> check status of the files

git commit -> commit the file

git commit -m 'comment' -> immediately add the commit comment on the command

git commit --amend -> to fix changes on the current commit instead of making a new
commit

git log -> look at the commit log

rm -rf .git [mac]


Remove-Item -Recurse -Force .git [windows powershell]
rmdir /s /q .git [windows cmd] (make sure to be in the root dir) -> remove
forcefully the .git to start over

Invoke-Item .\index.txt [w ps] -> open the file in the default app

git diff .\index.txt [mac] -> show the diff between staged & unstaged commit file

git reset -> reset back to a specific commit


--soft -> keep code changes, but erase the commit
--hard -> erase every changes after the specific commit

git show {hashcode} [mac] -> show the file

========= BRANCHING ==========


git branch -> see all branches
git branch -v -> see most recent commits for all branches

git restore the file


then
git checkout -b {name of the branch} -> create and switch to the new branch

git checkout {branch name} -> switch to the branch

to merge:
go back to the master branch
git merge {branch-name to be merged with master} -> merge branch-name dengan branch
sekarang

after merge:
delete the other branch
git branch -d {branch-name}
======== ALIASES ========
git config --global alias.s status -> set 's' as the alias for status (git status -
> git s)

git config --global --unset alias.s -> remove the alias

git stash -> stash away what we are working on temporarily instead of commit reset
etc.
git stash list -> check stash

git stash apply -> return the stash but it will still be in the stash list

git stash pop -> return stash and delete it from list

git stash apply {id} -> specific stash

git stash drop -> delete stash (default most recent)

git stash branch {branch-name} -> apply stash from a different branch to branch-
name

You might also like