Difference between revisions of "Short Notes on git"
(Created page with "== Basic Commands == The ''git'' has 3 "trees" maintained automatically within your local repo - "working copy" is the files you're actually working on, "index" is kind of st...")
Revision as of 14:48, 26 October 2016
The git has 3 "trees" maintained automatically within your local repo - "working copy" is the files you're actually working on, "index" is kind of staging area, and "head" is your last actual commit. You're working on your working copy, then add changes to the index, then push those to head locally, and finally push those to (remote) repo.
# two ways to check out a repo; 1) first local, then connect $ git init # init local copy $ git remote add origin <server> # connect it to remote # or, 2) checkout a remote repo straight away $ git clone /path/to/repo # create working copy of local repo $ git clone user@host:/path/to/repo # create working copy of remote repo $ git pull # update the local copy to the latest revision $ git diff <source> <dest> # view differences between "source" and "dest" branches $ git merge <branch> # merge changes from another branch (e.g. "master") # set meld as diff and merge tool; use --global to apply globally, not just per-repo $ git config difftool meld $ git config difftool.prompt false # don't ask each time whether to run meld $ git config mergetool meld # don't ask each time whether to run meld $ git config mergetool.prompt false $ git difftool # you need to use "difftool" to run meld for diff, not just `git diff` $ git mergetool # run this only after `git merge` if there are any conflicts to be resolved # getting the changes to the remote repo $ git add [-i] <file> # add changes from file(s) to index (-i = interactive) $ git commit -m 'message' # commit changes from index to head $ git push origin master # push changes from head to master branch, or $ git push origin <branch> # push changes to <branch> $ git checkout -- <file> # revert file and replace with current HEAD version, exc. of changes added to Index $ git fetch origin # fetch latest history from server $ git reset --hard origin/master # drop all local changes, incl. those in Index # branching $ git checkout -b <branch_name> # create a new branch, and switch to it $ git push origin <branch_name> # make the branch available to others # other stuff $ git tag <tag name> <commit id> # create tag from a commit $ git log --pretty=oneline [--author=<name>] # one-line per commit listing $ git log --graph --oneline --decorate --all # ascii tree of branches, tags, ... $ git log --name-status # list changed files
Using Git with gnome-keyring
sudo apt-get install libgnome-keyring-dev cd /usr/share/doc/git/contrib/credential/gnome-keyring sudo make git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring