Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Friday, September 30, 2011

Git resolve merge conflicts

So you have

$git merge repo
Auto-merging path/to/file1
Auto-merging path/to/file2
CONFLICT (content): Merge conflict in path/to/file3
Auto-merging path/to/file4
CONFLICT (content): Merge conflict in path/to/file5
Automatic merge failed; fix conflicts and then commit the result.

To fix:

For all files with conflicts, do:
1.vim path/to/file3 and then compare the text

<<<<<<<

=======

with

======

>>>>>>>
Make sure you delete those indicator lines too.

2. git update-index [path/to/file3]

source

Sunday, September 25, 2011

Github as the second remote

This is a brute-force way of setting up github as a second remote/backup to your code.

1. $ cp -r repo repo_backup
2. $ cd repo_backup and then vim .git/config
delete the old [remote "origin"]
3. $ git remote add origin git@github.com:username/repo_name. Now you should see its corresponding lines in .git/config
4. I want to push my local branch "b1" to a branch on github named "branch1", so I did git push -u origin b1:refs/heads/branch1

multiple git remotes

One is the real git remote, one is a backup I would like to have on github.


==============
.git/config's remote fetch = +refs/heads ...
explained here


Finally,
fetch = +refs/heads/*:refs/remotes/origin/*
That means if you do
git fetch origin
It will actually do:
git fetch origin +refs/heads/*:refs/remotes/origin/*
Which means a remote heads/foobar will be local remotes/origin/foobar, and the plus sign means they'll be updated even if they are not fast-forward.

answered by felipec

================
http://stackoverflow.com/questions/849308/pull-push-from-multiple-remote-locations/849960#849960

Friday, September 9, 2011

git edit commit message and push to github

Steps to edit a git commit message and also have it show up to Githb:

1. To edit your last commit message:

git commit --amend

2. Edit your commit message on top. If you're using vim, to save and quit, do esc+":wq"

3. Push to Github:

git push --force


Note that if you don't have the "--force", you'll get this error message:

$ git push
To git@github.com:your/repo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:your/repo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
So remember to git push --force!

Friday, August 5, 2011

git branch

git branch

git fetch origin
git co branchname

Sunday, July 3, 2011

bashrc improvements for git

show which brach on
git auto complete

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\t\[\033[ 00m\]:\[\033[01;32m\]\w\[\033[00m\]$(__git_ps1 " (%s)")\$ '


source /usr/local/etc/bash_completion.d/git-completion.bash

Sunday, March 27, 2011

Can't push on Github

When I tried to git push new commits into github, it asks:

Enter password to unlock the private key
An application wants access to the private key
'[my email]' but it is locked.

I tried all my passwords but it didn't work. Google didn't help much either.

Victor is here to help:

It means you password-protected your SSH keys, despite all the advice
against doing so.

The easiest fix is to blow up and re-generate your keys.

cd ~/.ssh
rm id_*
ssh-keygen
# Do NOT enter a password; just press Enter every time it asks a question
cat id_rsa.pub
# Go to GitHub -> account settings -> ssh public keys -> add another public key

Now I can finally navigate to my project directory and do
git push

Thursday, March 10, 2011

Setting up Github and RubyGems Profile for My Stuff

Set up Github

I found that the git configuration is expecting me to make a "ethrernet" project: "./.git/config: url = git@github.com:haoqili/ethernet.git"

So I'm going to set up my github account, which I got a few weeks ago. I followed these github bootcamp instructions to get my SSH keys.

Yay! It's done! https://github.com/haoqili/ethernet

Committing to Github from computer
  1. make edits
  2. git status
  3. git add [the modified files]
  4. git commit -m "message here"
  5. git push will push to github!
Setup RubyGems Profile btw, gemcutter.org redirects to rubygems.org
  1. sudo gem update --system
  2. bundle install ~ this adds Gemfile.lock
  3. vim VERSION ~ if you don't already have a "VERSION" file
  4. git add VERSION ~ put in "0.0.0" in it
  5. git commit -m "added a VRESION"
  6. git push
  7. rake release
If you get this error message for rake release (see below), this is because you don't have a VERSION file with "0.0.0" in it:

(in /home/haoqili/Desktop/rails/ethernet)
Committing ethernet.gemspec
Pushing master to origin
Tagging v
Pushing v to origin
Generated: ethernet.gemspec
ethernet.gemspec is valid.
  Successfully built RubyGem
  Name: ethernet
  Version: 
  File: ethernet-.gem
Executing "gem push ./pkg/ethernet-.gem":
gem push ./pkg/ethernet-.gem
Pushing gem to https://rubygems.org...
There was a problem saving your gem: Number is invalid
rake aborted!
Command failed with status (1): [gem push ./pkg/ethernet-.gem...]

(See full trace by running task with --trace)

Search for project name on rubygems.org. I have http://rubygems.org/gems/ethernet

Sunday, February 13, 2011

Git tutorial -- Getting started with git (hosting and cloning)

I have used git a bit in classes and for github projects created by others. But today I'm taking the initiative to learn it from scratch. My friend Phil set up a Ubuntu virtual machine for me on his server, where I plan to do a very small web project with dcluo. Git was not installed.

Creating a git repository on a directory for a project:

0. My directory where I want to make into a git repository is /var/www/game1. There is currently only 1 file inside it: index.html

1.* Install git from Ubuntu terminal: sudo apt-get install git-core git-doc
* See note below *

2. Create git repository: git init
Initialized empty Git repository in /var/www/game1/.git/

3. Check it's working: git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# index.html
nothing added to commit but untracked files present (use "git add" to track)

4. git config --global user.name "Your Name"
5. git config --global user.email youremail@email.com

6. git add index.html and add other files similarly

7. git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: index.html
#

8. git commit -a -m "brand new start" the "-a" adds all the changed files (yes, it's redundant here because I have added my only file in step 6, but it's good to know)
[master (root-commit) d38fbfd] brand new start
1 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 index.html

9. git status
# On branch master
nothing to commit (working directory clean)

10. git log note it doesn't say "commit #1", it's good because ordering by numbers would be confusing if you merge or revert commits in the future
commit d38fbfd10003a28859d5b943b729084bfcf6b78d
Author: HaoQi Li <youremail@email.com>
Date: Sun Feb 13 06:14:54 2011 -0500

brand new start

Getting that git repository directory on another machine:

11. On another machine, make a directory where you want to clone the repository. mkdir anotherDir

12. cd anotherDir

13. git clone haoqi@haoqi_s.host.com:/var/www/game1 . don't forget the dot at the end! It means copying to the the current directory.
Initialized empty Git repository in /path/to/anotherDir/.git/
The authenticity of host 'haoqi_s.host.com (209.143.128.58)' can't be established.
RSA key fingerprint is 58:9c:96:f9:7c:39:3c:78:07:8c:40:59:a5:4b:34:9b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'haoqi_s.host.com,209.143.128.58' (RSA) to the list of known hosts.
haoqi@haoqi_s.host.com's password:
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

If instead you get this error below, check that you're in a place where you can do git. In my case, I did "ssh scripts.mit.edu" right before running the git clone, but git doesn't work inside MIT scripts.
Cloning into ....
The authenticity of host 'haoqi_s.host.com (209.143.128.58)' can't be established.
RSA key fingerprint is 58:9c:96:f9:7c:39:3c:78:07:8c:40:59:a5:4b:34:9b.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/current/machines/home/dir/.ssh/known_hosts).
Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly

14. git log
commit d38fbfd10003a28859d5b943b729084bfcf6b78d
Author: HaoQi Li
Date: Sun Feb 13 06:14:54 2011 -0500

brand new start

Yay success!

==========
Edit 3/10:
Github has new tutorials that will help you get started.
1. Set up git in Linux
2. Create a repository
3. Fork a repository
4. Follow a friend