this page contains frequently used git commands when working on git projects with more than one developer. it contains:
Global setup:Download and install Git git config --global user.name "Your Name" git config --global user.email js@lastlog.de Add your public key Next steps:mkdir nNull cd nNull git init touch README git add README git commit -m 'first commit' git remote add origin git@github.com:qknight/nNull.git git push origin master Existing Git Repo?cd existing_git_repo git remote add origin git@github.com:qknight/nNull.git git push origin master frequently used git commandsadding a new mastergit remote add crei http://git.gitorious.org/evopedia/evopedia.git my .git/config [core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[branch "master"]
[remote "origin"]
url = git@github.com:qknight/evopedia.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "crei"]
url = http://git.gitorious.org/evopedia/evopedia.git
fetch = +refs/heads/*:refs/remotes/crei/*
fetch & mergelet's merge my current head with crei/master using a fetch & merge operation. as mine src.pri is outdated i decide to use his src.pri by overwriting it with a checkout. git fetch crei master git merge crei/master git checkout --theirs src.pri git add src.pri git commit push my stuff to github.comafterwards i commit his changes and then i push it to my repository at github.com git add <several files> git commit git push origin master upload changes done in windowsproblem: had to work with git on windows but i did not want to push then changes from windows. instead i did use it the normal way: git add <stuff>; git commit; finally i used zip to make an archive of the whole direcotory (where the git stuff was in). next i extracted it on linux but this resulted in crazy things as well files were different (encoding problems). cloning it locally fixed it. finally i reseted the head and recommited everything from scratch (but this time as my main user). in retrospective i could have used the local git socked based service to clone it from windows directly. i had to use this method because all the files had a different encoding and i couldn't use the changed files directly. see 'recommit' at [2]. on windows tar cf evopedia.tar evopedia/ now on the linux machine: cp evopedia.tar /tmp tar xf evopedia.tar mkdir /tmp/evopedia-windows-clone/ cd /tmp/evopedia-windows-clone/ git clone /tmp/evopedia/ check that your wanted git commit is there git log next copy the git configuration from the place the project is in usually cp ~/Desktop/projects/eopedia/.git/config .git/ now reset the last commit (one can directly recommit afterwards) git reset --soft HEAD^ to check if everything is sane git status git commit now upload the stuff to the remote: origin master git push origin master got regression?in case you get regression, make a commit with the current work git status git add .... various files git commit next we want to see a list of previous commits git log which will print out all your commits with a SHA1 sum, find the commit's SHA1 sum to branch into your previous commit git checkout -b aNewBranch e0184ebe889cb4f4fb70a50f1523a77b2b6070a9 now you can play with the 'previous commit' as all files in the current dir are 'timetraveled backwards' as i usually work with cmake and out of source build it's simply rm -Rf build/* cd build cmake .. make after the software has built and you found out that it really worked in the past but does not work in head it's a clear sign of regression (which happens often when not using class tests). therefore i started to maintain a test script, to monitor parameters as:
finally it's time to go head, do this: git checkout master and you are back, you can now remove the branch (or as you desire leave it for further experiments). Your branch is ahead of 'origin/master' by 4 commitsrun: git status to get this message it happens when you pulled from another master which has several commits, which might already be merged with your local repository. but you need to upload the local repository to _your_ online repository (for instance github.com). to see what is going on: git diff origin/master in order to upload my local repo to my online repo, i type: git push origin master links
|