Git ~ Everything About

Git ~ Everything About

The Book of Git Ovde sam stao: http://git-scm.com/book/en/Git-Tools-Interactive-Staging :: Git

http://git-scm.com/book » Git - Book http://gitready.com/ :: git ready » learn git one commit at a time

git commit –amend http://git-scm.com/book/en/Git-Basics-Undoing-Things#Changing-Your-Last-Commit » Git

git clone options * –origin (-o ) Instead of using the remote name origin to keep track of the upstream repository, use . http://git-scm.com/docs/git-clone » Git

* <directory>
The name of a new directory to clone into. The "humanish" part of the source repository is used
if no directory is explicitly given (repo for /path/to/repo.git and foo for host.xz:foo/.git).
Cloning into an existing directory is only allowed if the directory is empty.

Git URLs: http://git-scm.com/docs/git-clone » Git http://stackoverflow.com/questions/1558719/using-a-remote-repository-with-non-standard-port » git - Using a remote repository with non-standard port - Stack Overflow

If you clone a repository, the command automatically adds that remote repository under the name origin.
So, git fetch origin fetches any new work that has been pushed to that server since you cloned (or last fetched from) it.
It’s important to note that the fetch command pulls the data to your local repository — it doesn’t automatically
merge it with any of your work or modify what you’re currently working on. You have to merge it
manually into your work when you’re ready.

You can use the git pull command to automatically fetch and then merge a remote branch into your current branch.

Running git pull generally fetches data from the server you originally cloned from and automatically tries to
merge it into the code you’re currently working on.

If you want to push your master branch to your origin server (again, cloning generally sets up both of those names for you automatically),
then you can run this to push your work back up to the server:

Cloning sets up both of those names (branch named master and remote named origin) for you automatically!

When you clone a repository, it generally automatically creates a master branch that tracks origin/master.

How does Git know what branch you’re currently on? It keeps a special pointer called HEAD. The git branch command only created a new branch — it didn’t switch to that branch.

$ git push origin master

Branching Explained http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging » Git

After you’ve resolved each of these sections in each conflicted file, run git add on each file to mark
it as resolved. Staging the file marks it as resolved in Git.

http://git-scm.com/book/en/Git-Branching-Remote-Branches » Git

Deleting Remote Branches:
    http://git-scm.com/book/en/Git-Branching-Remote-Branches » Git

About rebase: In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase. Caution: If you treat rebasing as a way to clean up and work with commits before you push them, and if you only rebase commits that have never been available publicly, then you’ll be fine.

Git Server You’ll notice that it generally takes a tiny amount of resources to host a Git repository, so you’ll rarely need to use an entire server for it.

A remote repository is generally a bare repository — a Git repository that has no working directory. Because the repository is only used as a collaboration point, there is no reason to have a snapshot checked out on disk; it’s just the Git data. In the simplest terms, a bare repository is the contents of your project’s .git directory and nothing else.

Local Protocol - remote repository is in another directory on disk. http://git-scm.com/book/en/Git-on-the-Server-The-Protocols#Local-Protocol » Git

It’s important to note that this is literally all you need to do to run a useful Git server to which several people have access — just add SSH-able accounts on a server, and stick a bare repository somewhere that all those users have read and write access to. You’re ready to go — nothing else needed.

http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server » Git
As an extra precaution, you can easily restrict the 'git' user to only doing Git activities with
a limited shell tool called git-shell that comes with Git

http://www.cyberciti.biz/tips/how-do-i-find-out-what-shell-im-using.html » How do I find out what shell I’m using?

What does this post-update hook do?

Git Cheat Sheet: http://zrusin.blogspot.com/2007/09/git-cheat-sheet.html » Zack Rusin: Git cheat sheet

GitHub Usage http://git-scm.com/book/en/Git-on-the-Server-Hosted-Git » Git Forking Projects: If you want to contribute to an existing project to which you don’t have push access, GitHub encourages forking the project.

http://betterexplained.com/articles/aha-moments-when-learning-git/ » Aha! Moments When Learning Git | BetterExplained http://www.sbf5.com/~cduan/technical/git/ » Understanding Git Conceptually

Git Immersion

Great tips: http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html :: git ready » what’s inside your .git directory http://norbauer.com/notebooks/code/notes/git-revert-reset-a-single-file :: git: revert (reset) a single file

GitFlow: http://nvie.com/posts/a-successful-git-branching-model/ :: A successful Git branching model » nvie.com http://vimeo.com/16018419 :: A short introduction to Git Flow on Vimeo http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/ :: Why aren’t you using git-flow? - Jeff Kreeftmeijer http://yakiloo.com/getting-started-git-flow/ :: Getting Started – Git-Flow « Some thoughts, ideas and fun!!!

http://dev.datasift.com/blog/hubflow-github-and-gitflow-model-together :: HubFlow - GitHub and the GitFlow Model Together | DataSift Developers
    http://datasift.github.com/gitflow/ :: HubFlow: GitFlow For GitHub


[Git: A simple workflow, commands, and usage | Geek Gumbo](http://www.geekgumbo.com/2011/08/04/git-a-simple-workflow-commands-usage/)

Git on Windows

GIT on Windows, Again http://haacked.com/archive/2011/12/19/get-git-for-windows.aspx » Configure Git in PowerShell So You Don’t Have to Enter Your Password All the Damn Time

http://marklodato.github.com/visual-git-guide/index-en.html :: A Visual Git Reference

Git tip: Changing your mind: Push pending changes to a (not-yet existing) new branch http://alexander.kirk.at/2012/02/15/git-tip-changing-your-mind-push-pending-changes-to-a-not-yet-existing-new-branch/


Learning resources

Git in 5 Minutes Don’t Be Afraid of Git: The Basics

GitGuys

Bits and Pieces

Simple way not ty type username+password everytime you make a git push: “%USERPROFILE%.git-credentials”

Submodules

First time, to init submodules, you must type:

git submodule update --init

Later, to update, type:

git pull --recurse-submodules  # actualy, not enough

Initialy, to add submodules, you would use:

git submodule add git@mygithost:some subdir/some

Best output (more info)

git log --graph --pretty=format:"%s * %an, %ar"

Aliases:

git config --global alias.mylog "log --graph --pretty=format:'%s * %an, %ar'"

git config --global alias.st "status"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.ci "commit"

Multiple Git in same directory

How to have two git repositories in the same directory Multiple working folders with single GIT repository

git --work-tree=where/my/code/is --git-dir=some/path/to/my/.git status

I same as using two environment variables: GIT_DIR (defaults to .git) + GIT_WORK_TREE (where the data is)

unset GIT_INDEX_FILE
export GIT_WORK_TREE=/var/www/example/
export GIT_DIR=/home/mark/test/.git/

Manage a Website with Git

git - Reuse GIT_WORK_TREE Using Git to manage a web site Using Git to Maintain Your Website | danielmiessler.com

Resolving Conflicts

Merging With a Conflict: Conflicts And Resolutions Resolving merge conflicts in Git - Genomewiki Git User’s Manual (for version 1.5.3 or newer)

Git Flow

Installing Git-flow in Windows

Download getopt.exe from Binaries and copy it to Git\bin directory. Then, in Git directory (c:\Program Files (x86)\Git) type:

git clone –recursive git://github.com/nvie/gitflow.git
cd gitflow/contrib
msysgit-install.cmd "C:\Program Files (x86)\Git"

Excersizes

Exercise no 1

i’ve created a new repo @um-1764.conepuppy.com:/home/git-repo/dating-playground.git you need to clone it and I’m gonna ask everyone to create one hotfix over there (using git flow) in that hotfix, edit file “names” and add your name to the list we need to make sure you’re all comfortable with git and git flow if you have any troubles, please feel free to hit me up, or ask on this chat thanks and tommorow we’re gonna do another exercise, and one every day until we cover everything everyone needs to know

git clone vcolovic@um-1764.conepuppy.com:/home/git-repo/dating-playground.git git checkout develop

procedura je manje vise sledeca objavis da hoces da radis hotfix prebacis se na develop granu kod sebe, uradis pull (i push ako si imao nesto sto nije otislo) prebacis se na master granu kod sebe i uradis pull (ne bi trebalo da imas sta da pushujes odavde) kazes git flow hotfix start v0.0.11 editujes fajl sa imenima git add names git commit -m “added my name” git flow hotfix finish v0.0.11 git checkout develop && git push git checkout master && git push git push –tags

to bi bilo manje vise to

The same, without git flow:

git checkout develop && git pull
git checkout master && git pull

git checkout -b hotfix/v0.0.13 master
Switched to a new branch 'hotfix/v0.0.13'

nano names
git status
git add names
git ci -m "names: updated without git flow"

git checkout master
git merge --no-ff hotfix/v0.0.13
git tag -a v0.0.13

git checkout develop
git merge --no-ff hotfix/v0.0.13

git branch -d hotfix/v0.0.13
git push

git checkout master
git push
git push --tags

Exercise no 2

create your own feature branch based on develop do some commits ocassionally pull develop branch at the end of your day finish your feature branch (fully merge with develop), and push result to origin

git flow feature start myfeature

git flow feature finish myfeature

Great .gitignore collection is found in this gitignore project 1: https://github.com/github/gitignore


GUI Mergetool (Difftool) for GIT And Editor

Using git mergetool and difftool under Windows | blog… not another yet Setting Up Git in Windows with Diffmerge, Powershell, Posh-Git, and Console2 - CodeProject Adam Stankiewicz : Use Sublime Text 2 as Git mergetool

Git Environment on Windows - Mark Embling

Git for Windows tip: Use P4Merge as mergetool | danlimerick P4Merge Alternatives for Windows - AlternativeTo.net Comparison of file comparison tools - Wikipedia, the free encyclopedia Git on Windows: How do you set up a mergetool? - Stack Overflow Setup p4merge as mergetool and difftool for git in windows (found here: http://stackoverflow.com/questions/426026/git-on-windows-how-do-you-set-up-a-mergetool) — Gist Resolving code conflict using p4merge with git on Windows - Gong Cheng’s blog - Site Home - MSDN Blogs

Windows Git Diff/Merge Tool Configuration — Gist shell script that configures git to use WinMerge as the default tool to handle conflicts — Gist

jdonley83 | Setting Up Git in Windows with Diffmerge, Powershell, Posh-Git, and Console2

Using KDiff3 as Git GUI Merge Tool on Windows XP and Windows 7 - Blog - MainelyDesign.com

SourceGear | DiffMerge | overview

P4Merge Perforce Visual Merge and Diff Tools | Perforce

Diffuse

Beyond Compare

Meld Portable Meld on Windows « Saher El-Neklawy’s Blog

TortoiseMerge http://stackoverflow.com/a/460348/1579985

http://stackoverflow.com/a/9610494/1579985

Araxis Merge: Two and Three-Way File Comparison, Merging and Folder Synchronization Software

Editor: Git for Windows tip: setting an editor | danlimerick


An Illustrated Guide to Git on Windows

10 things I hate about Git « Steve Bennett blogs

Ignoring local modifications to tracked files

Problem: I want to distribute config file to all the developers, but I don’t want their changes to be propagated.

Wrong idea: Untrack Files In Git Repos Without Deleting Them | Arlo Carreon

Better one: git update-index –assume-unchanged FILENAME git tip: Ignoring modifications to tracked files | tail -f findings.out To list these files, use: git ls-files -v -v switch: shows the file status, but use lowercase letters for files that are marked as assume unchanged These both work: git ls-files -v | grep “^[[:lower:]]” git ls-files -v | grep “^[a-z]”

It’s definitely skip-worktree bit. The solution to not-resetting skip-worktree bit is called Sparse checkout. Turn it on with core.sparseCheckout and then edit the $GIT_DIR/info/sparse-checkout.

Why not using sample file? And let users create their “.gitignored” config files? The only thing missing in that scenario is that users are not notified if something changes in config files.

Keep local modifications in Git-tracked files | Virtuous Code fallengamer: git assume-unchanged vs skip-worktree

Windows problem with submodules

Never ever add a submodule using path wint backslash (\). At the beginning, it looks ok, but when you try anything like git submodule update it blows with an error:

No submodule mapping found in .gitmodules for path

The reason wat that I used backslash-es, a I shouldn’t. http://code.google.com/p/msysgit/issues/detail?id=431

x

git remote add origin ssh://vcolovic@um-1764.conepuppy.com:4322/home/git-repo/dating-devbox.git git push origin master

Two ways to clone repository:

git clone --recursive ssh://vcolovic@um-1764.conepuppy.com:4322/home/git-repo/dating-devbox.git

or:

git clone ssh://vcolovic@um-1764.conepuppy.com:4322/home/git-repo/dating-devbox.git
git submodule update --init --recursive

Whenever you want to update submodules, type: git submodule update –recursive (for old git it was: git submodule foreach git pull)

And pull with it (but there are differences, the first one is better): git pull –recurse-submodules

The best is to use:

alias update_submodules='git pull --recurse-submodules && git submodule update --recursive'

or better yet:
    git config alias.pullall '!f(){ git pull "$@" && git submodule update --init --recursive; }; f'

Pull automatically update submodules? Working with Git on Windows

Git update all the modules

git submodule foreach git pull origin master

or sometimes: git submodule foreach git pull

How to update submodules in git | The Missing Readme

How to edit some older commit, still not pushed?

  • git reflog / To get a list of where HEAD has been lately. Even nicer git reflog --oneline --decorate Note that, at the same time git log --oneline --decorate doesn’t show you that commit. Even nicer is: git show-branch –sha1 –reflog

  • Write down the <hash> of the real last commit

  • git reset --soft <hash> to the wanted one

http://clipboard.com/clip/LQMhzpWAH8xGNpO8uEkJ0rbdpSMWbkeZCmme EDITOR=: http://stackoverflow.com/a/3549166/1579985

Fun with the upcoming 1.7 release of Git: rebase –interactive –autosquash - Technosorcery Updated git rebase –interactive –autosquash commit preparation - Technosorcery

In short:

# Stage changes (fix) that you want
git add ...

# Nicely list commits
git log --oneline --decorate

# Copy to clipboard hash of the commit that you want to change With
# that hash, perform the commit to fix broken commit. There are two
# variants: --fixup and --squash, with subtle differences
#
git commit --squash=<HASH>

# If you check, it's another commit with changed (prefixed) subject
# line. Don't worry, rebase will do the magic, and glue that new
# commit to the broken one, on the same location.
#
git rebase --interactive --autosquash <HASH>~1

Simple Git operation that was not so obvious to me:

If you did for example:

git reset --soft HEAD~1

And then you changed your mind? Want to go back to last commit…

The answer was to lookup for last commit hash. I tried with git log. No way amigo. Solution was (the only one): git reflog.

And then, after copy-pasting hash, simple git reset --soft <HASH>.

For me, this was not so obvious. I expected git log to show me what I wanted.

List files

Retrieve the last modification date of a file in a git repository.

List files showing date of last commit on every one:

git ls-tree -r --name-only HEAD | while read filename; do echo "$(git log -1 --format="%ad" -- $filename) $filename"; done;

http://serverfault.com/a/401450/152357

Graphical Git Clients for Linux

Git GUI tools on Linux: Gitg is by far the best, Giggle is solid second.

We can separate in two tribes:

  1. For Git operations: create commits by staging changes and writing a commit message, remote repositories and branches, etc.

    Official is:

    • git gui but UI and fonts look awful.
  2. For viewing history: viewing a repository through the commit log, selecting a details of commits, including diffs, maybe git blame on files.

    Official:

    • gitk, also very ugly but still better.

    Alternatives:

    • giggle: slow on start, very nice history, has browse files but no git blame on files.
  3. Both 1. & 2. No official application for this.

    • gitg can both view and make commits. And it’s nice and fast. You can also view files bot in blame mode.

    • SmartGit is just too much - written in Java. Seems to be pretty feature rich. It allows committing, rebasing, visualizing branch history. It’s not open source but is free to use. Anyway, SmartGit install from PPA

    • git-cola has all the operations, and as an extra, has Git DAG (git dag: An advanced DAG visualizer) view which is very interesting, but not tightly integrated.


Basic Git Operations

Basic commit

git add . && git commit -am "<commit message>"

Fastest way to commit

This command will add and commit all the modified files, but not newly created files
a.k.a. doesn’t add or commit untracked files

git commit -am  "<commit message>"
date 21. Dec 2016 | modified 10. Jun 2024
filename: Git » Everything About