User Tools

Site Tools


git:git_cheatsheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git:git_cheatsheet [2012/11/02 16:49] devagit:git_cheatsheet [2017/02/21 20:20] (current) deva
Line 1: Line 1:
 ======GIT CheatSheet====== ======GIT CheatSheet======
 +
 +=====See diff between local commits and remote master=====
 +<code>
 +git diff master origin/master
 +</code>
 +
 +=====Pull from origin and overwrite local changes=====
 +<code>
 +git reset --hard; git pull -Xtheirs
 +</code>
 +Useful if you have local changes that you do no longer need.
 +
 =====Mark file as 'unchanged'===== =====Mark file as 'unchanged'=====
 This will ignore the file on all commits using the -a argument. This will ignore the file on all commits using the -a argument.
Line 36: Line 48:
 ====Create==== ====Create====
 <code> <code>
 +# create tag locally:
 git tag -a v1.4 -m 'version 1.4' git tag -a v1.4 -m 'version 1.4'
 +
 +# push tag to server:
 +git push –-tags
 </code> </code>
  
Line 54: Line 70:
 </code> </code>
  
-====Push==== +====Delete==== 
-By default, the ‘git push’ command will not transfer tags to remote servers. To do so, you have to explicitly add a –-tags to the ‘git push’ command.+<code> 
 +# delete tag locally: 
 +git tag -d v1.0 
 + 
 +push tag deletion to origin: 
 +git push origin :refs/tags/v1.
 +</code>
  
 =====Branches===== =====Branches=====
Line 63: Line 85:
 </code> </code>
  
 +====Create branch====
 +Create and switch to:
 +<code>
 +git checkout -b [branchname]
 +</code>
 +
 +Just create:
 +<code>
 +git branch [branchname]
 +</code>
 +
 +Push to server:
 +<code>
 +git push -u origin [branchname]
 +</code>
 ====Switch to branch==== ====Switch to branch====
 <code> <code>
Line 68: Line 105:
 </code> </code>
  
 +====Delete branch====
 +<code>
 +git branch -d branchname
 +git push origin --delete branchname
 +</code>
  
 +====Fecth branches from server====
 +<code>
 +git fetch --all
 +</code>
 =====CVS 2 GIT===== =====CVS 2 GIT=====
 <code> <code>
Line 78: Line 124:
 =====Branching/Merging===== =====Branching/Merging=====
 From: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging From: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
 +
 +=====Creating a new repository=====
 +<code>
 +As root:
 +mkdir /home/git/repos/[reponame].git
 +cd /home/git/repos/[reponame].git
 +git --bare init
 +git update-server-info
 +chown -R apache:apache /home/git/repos/[repomame].git
 +</code>
 +
 +Now clone the project on a client, add some files and commit them.
 +When pushing them for the first time use the following command:
 +<code>
 +git push origin master
 +</code>
 +NOTE: If this is done by the usual 'git push' command, a 'No refs in common and none specified; doing nothing.' error will be issued.
 +
 +=====Set up repository mirror=====
 +From: https://help.github.com/articles/duplicating-a-repository/
 +<code>
 +# Create a bare clone of the repository.
 +git clone --bare https://github.com/exampleuser/old-repository.git
 +
 +# Mirror-push to the new repository.
 +cd old-repository.git
 +git push --mirror https://github.com/exampleuser/new-repository.git
 +</code>
 +
 +=====Move single directory to its own repository=====
 +http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475
 +
 +=====Replace email address in commits and tags======
 +https://help.github.com/articles/changing-author-info/
 +
 +NOTE: The way the push command is performed is important in order to overwrite bot commits and tags.
git/git_cheatsheet.1351871343.txt.gz · Last modified: 2012/11/02 16:49 by deva