I’m very noob with git and I always screw everything when someone clone one of my repo, contributes and asks me to merge the changes.
Now I found an easy way to merge commits from another repository. Here is a simple way to handle this. We will get changes from project1_modified to merge it into our project1 repository. This is not the fastest way or maybe not the optimal way, but I found it to work reliabily.
cd /path/to/projects git clone git://remote/project1_modified cd my_project1 git checkout master git remote add modified ../project1_modified/ git remote update git checkout -b new_code git merge modified/master git checkout master git merge new_code git branch -d new_code
This process will makes you download the repository of the people who contributed to the code, then you add it as a remote sources into your project, you create a new branch where you will do the merge, if something is wrong you will be able to manage conflicts easily. Once you tried the code and you are fine, you need to merge this branch to master and then, when you are done, you can delete the branch.
If later you need to get new commits from the other repo, it become easier.
cd /path/to/projects cd project1_modified git pull cd ../my_project1 git pull modified git merge modified/master
And you are done !
Here is an how-to in order to make a git repository available for cloning through a simple http server. This method only allow people to fetch the repository, not to push. I wanted to set-up this to get my code, I don’t plan to have any commit on it from other people at this time so it’s enough.
In a folder publicly available from your http server clone your repository in bare mode. As explained in the [https://git-scm.com/book/tr/v2/Git-on-the-Server-The-Protocols](man page) :
cd /var/www/htdocs/some-path/ git clone --bare /path/to/git_project gitproject.git cd gitproject.git git update-server-info mv hooks/post-update.sample hooks/post-update chmod o+x hooks/post-update
Then you will be able to clone the repository with
git clone https://your-hostname/some-path/gitproject.git
I’ve lost time because I did not execute git update-server-info so the clone wasn’t possible.
Here is my git cheat sheet ! Because I don’t like git I never remember how to do X or Y with it so I need to write down simple commands ! (I am used to darcs and mercurial but with the “git trend” I need to learn it and use it).
Undo uncommited changes on a tracked file
git reset --hard
Get the latest version before working
Make a commit containing all tracked files
git commit -m "Commit message" -a
Send the commit to the repository
You have a git repository where you work in, and you would like to work on a clone of it and push the data back to it ? You may encounter issues if your git repository isn’t a bare one. I have been facing this problem by using gitit, which works with a non-bare git repository.
What is a bare git repository ?
Here is how to create a bare repository and what it looks like.
git init --bare repo ls -a repo/ . HEAD config hooks objects .. branches description info refs
You can’t work in this, but this is the kind of repository that should be used to store/push/clone etc..
What is a non-bare git repository ?
Here is how to create a non-bare repository and what it looks like.
git init repo2 solene@cbc:~/tmp/r% ls -a repo2 . .. .git
You may use this one for local use, but you may want to clone it later, and work with this repository and doing push/pull. That’s how gitit works, it has a folder “wikidata” that should be initiated as git, and it will works locally. But if you want to clone it on your computer, work on the documentation and then push your changes to gitit, you may get this error when pushing :
Problem when pushing
I cloned the repository, made changes, committed and now I want to push, but no…
Décompte des objets: 3, fait. Écriture des objets: 100% (3/3), 232 bytes | 0 bytes/s, fait. Total 3 (delta 0), reused 0 (delta 0) remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository remote: error: is denied, because it will make the index and work tree inconsistent remote: error: with what you pushed, and will require 'git reset --hard' to match remote: error: the work tree to HEAD. remote: error: remote: error: You can set 'receive.denyCurrentBranch' configuration variable to remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into remote: error: its current branch; however, this is not recommended unless you remote: error: arranged to update its work tree to match what you pushed in some remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behaviour, set remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. ! [remote rejected] master -> master (branch is currently checked out)
git is unhappy, I can’t push
You can fix this “problem” by changing a config in the server repository with this command :
git config --local receive.denyCurrentBranch updateInstead
Now you should be able to push to your non-bare repository.