Skip to content

francesco-cadei/git-magit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

first example is for git (command-line), second is for magit

intro

git
DVCS (Distributed Version Control System)

advantages of a VCS:

  • collaboration
  • storing/restoring versions
  • understanding changes
  • backup

basics

init

  • create .git/
  • create HEAD file referencing master (no commit)
git init [<dir>]
magit-init

status

displays paths that:

untracked
not in index file (not ignored by .gitignore)
unstaged
working tree state different from index virtual working tree state
staged
index virtual working tree state different from HEAD referenced branch snapshot
git status
C-x g

stage

update index to set paths to staged

git add <path>..
s: single
S: all

unstage

update index to set paths to untracked/unstaged

git reset HEAD <path>..
u: single
U: all

commit

snapshot of the index changes and HEAD branch update

git commit
git commit --amend
c c: commit
c a: amend
  • the amend option only update last commit

branch

manage branches

git branch <branch>
git branch -d <branch>: if merged
git branch -D <branch>: if not merged
b c: create and checkout
b k: delete branch

checkout

updates files in the working tree to match the version in the snapshot

git checkout <branch>
b b:

merge

merge the current branch with another

git merge <branch>
m m:
fast forward
update current branch to the newest, no commit
3-way merge
resolve two branch last commits in a new commit in which conflicts are solved row by row

syncing

remote

manage remote urls

git remote add <name> <url>
git remote rm <url>
git remote rename <old> <new>
magit-remote-...

clone

git clone <url>
magit-clone

push

git push [<remote> <branch>]
P p:

to prevent you from overwriting commits, git won’t let you push when it results in a non fast-forward merge in the destination repository.

  • --force-with-lease force push ensuring none of your teammates have committed

if the remote history has diverged from your history, you need to fetch the remote branch and merge it into your local one, then try pushing again.

fetch

git fetch [<remote> <branch>]
f p:
pull
fetch + merge

intermediate

stash

git stash: only tracked
git stash -u: also untracked
git stash -a: also untracked and ignored

git stash pop
git stash apply
z z: save
z p: pop
z a: apply

rebase

apply commits of current branch to the head of another

git rebase <branch>
git rebase -i <branch>
r e:
r i:

interactively permit to manage history of commit: squashing, fixuping, deleting, ordering..

  • --autostash in order: stash, rebase and stash pop uncommitted changes

tag

naming convention v0.0.1

git tag <tag>
git push origin --tags

git tag -d <tag>
git push origin :<tag>
t t:
P t:

t k:
t p:

undoing

revert

apply reverse changes

git revert <commit>..
git revert -n <commit>: no commit (change only working directory and index)
V V:
v:

reset

reset the history

git reset ..
X ..
soft
HEAD
mixed
HEAD, index (default)
hard
HEAD, index, working tree

navigation:

  • HEAD^n specify which parent follow
  • HEAD~n specify for how many

(characters can be combined: HEAD^x~y)

logging

log the working file magit-log-buffer-file

reflog

git reflog
l H:
  • checkout HEAD@{n} to recall a state

chunks

chunks can be managed from magit-status

s: stage
u: unstage

k: discard
v: revert

About

Quick introduction to git and magit.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published