last day (14 days later) » 

7:15 AM
1
A: git, syncing a new repository

Andrew CAdd -f to your git push line to force push git push -f origin master This will throw out whatever existing history of master the remote repository had. If you want to preserve your existing history you have more or less 3 choices 1) Just start a new repository since the projects seem unrelat...

 
so this will force a push, but not affect the commit history right? I'll still be able to see the old changes to the previous files?
 
"This will throw out", so no. If you want to keep the old history you have a couple of choices. I'll edit.
 
Also the projects are related, but its a complicated situation. Regardless I tried method two, but I am getting an usage error.
 
you may need to add '--root' to the rebase line, or redo the steps so that you copy your new project in after you are already checked out to a branch based off of origin/master. Post the error message if you are stuck.
 
After adding --root, I received the message fatal: Needed a single revision. If I want to start over, what order would I execute the commands in?
 
7:15 AM
You have a zip or tarball of the new source? After you fetch I would git checkout -b new_proj origin/master then git rm everything, and extract the source onto that.
 
Mind if you chat me through the process?
I want to accept your answer, I just want to work it out first
 
no problem
 
so I had executed the commands listed in my question in that order
How would I undo them in order to make a new branch?
That seems like the best option here
 
so the new source, whatever it is that you added with "git add -A", is that just a bunch of files you have? Or is there history to it?
 
no history to it, just a bunch of files
but its actually the same repository
just significantly changed and not synced with the latest commit
which I won't want to pull
 
7:20 AM
ok, and you have them in a zip/tar or in another directory outside the repo to copy from ?
type "git branch -vv"
normally you master would show like
dev_spiderman 23857f1 [origin/dev_spiderman]
except master and origin/master, to show it was tracking
I presume yours is missing the [origin/master] part ?
 
It prints my commit message with an asterisk beforehand
 
ok, so your master is entirely unrelated to origin/master
 
well I initiated a new repo
then fetched my old rep
 
oh
 
repo*
 
7:22 AM
ok
 
I want to associate them basically
 
you fetched from github ? Or the other repo you just created
 
And for reference and possibly debugging purposes, I want to keep the old commit history
from github
 
ok
and you did the init first then remote add again? Normally it would be easier to just git clone but no matter
so if you did init then remote add
you would do git reset --hard origin/master to get your current branch set to master
then
git branch --set-upstream-to=origin/master
 
but I don't want to override my repo with the changes from the latest commit
wouldn't git reset --hard do that?
 
7:26 AM
git reset --hard is going to overwrite your index and your working directory
 
ok
I'll try it then
 
so anything in the working directory is gone for good
but you have your new changes elsewhere, so no problems
ok - next step is going to be "git rm -rf *" to nuke everything from the working directory and index
then, extract your new source code somehow (unzip, untar, copy over) - using normal file system operation
then 'git add' everything
and git commit
 
wait, by working directory, you are referring to what? I though the working directory was the new directory?
 
if you do
mkdir new_repo
cd new_repo
git init
the repository is inside the hidden .git directory
the working directory is all the normal files that edit and modify
 
can I just delete .git from the directory and then git init all over again?
 
7:29 AM
that would refetch everything from github
if you did that I would say do a clone instead
since that sets up the branch from the get go without any other steps
 
alright I'll go with the clone
so what commands would I have to do then?
rm -rf .git
git init
 
no non o
just rm -rf the entire repository
then 'git clone git@github.....'
 
I don't think we're on the same page here, I'm sorry, let me explain one more time
I have a directory that I want to basically sync the repository to
I don't want to download the contents from github, I want to upload this directory
but keep the history of the old contents for reference
 
right so the problem is
in order to create a new commit and preserve the original history, you have to have the old history present
you can't attach your new directory without having the other stuff.
unless you went in as a separate branch unrelated to the original project
if you want to be able to do 'git log' and have the history go from your new project to the old project, you have to get whatever is on github local
if you don't care, then you can just push a new branch I would imagine
 
whichever way you think would be most logical
 
7:33 AM
it's not me who lives with the consequences
if there is shared code between the two projects, and you have to support the old version and the new version and merge fixes from old to new then you would definitely want them to be connected
 
so new branch then?
that's fine by me
 
I presume it would work. I don't use git hub
 
oh
 
git normally just prints out a warning that says "no common commits" but lets it go through
so do your original steps
 
well you seem to know a lot about git anyway
 
7:35 AM
and just do
git push -f origin master:new_project
to push your local master to a remote branch named new_project
 
so I typically run this for commits:
git ad -A
git commit -m ""
git push origin master
 
we have about 200 users at my work and maybe 50 repos we support over 5 different geographies, so I spend more time then I want dealing with git
 
then from there on, in order to push to the new branch, what would I have to change?
 
so do you have a push.default set?
 
no
 
7:36 AM
did you do "git config --global push.default blah"
ok
are you using git older than 2.X or newer than 2.0 ?
because they changed the stupid defaults in 2.0
 
1.7.2.5
 
I can't remember if that will screw us up here or not
yikes. Time to upgrade. At least to 1.8
 
should I update first?
alright
 
nah, you are just missing a lot of new features
ok so
git push origin master says
push my master, and overwrite the remote master
your master isn't related to the remote master though, hence the error
so try 'git push origin master:new_proj'
or whatever name you want instead of new_proj
 
ok
then I should be good?
 
7:39 AM
sort of
 
but then how do I push/pull from that branch?
 
we'd need to get you a local branch is all
presuming it goes through you would just type "git checkout new_proj" to have a working local branch, and you would confirm with "git branch -vv" as before
 
so this went through to the new branch
ok
got a "switched too a new branch 'name' "
 
and git branch -vv shows [origin/new branch name] ?
 
yes
 
7:41 AM
and git status should say
up to date or something
 
yah
so now in order to push/pull
I would type git push/pull origin "name"
 
you just push/pull same as ever, except you are on a different branch name now
 
oh ok
so that's what checkout does
 
normally no, if you only have "origin" you can just do "git pull" and "git push" and it will work
as long as your branch tracks
git will use whatever the tracking info is
 
alright, you've been a tremendous help
I wish I could repay you with more than 15 rep
 
7:43 AM
no problem. I would recommend you set
git config --global push.default tracking
I don't know why, but the defaults git uses for working with remotes are not good.
 
replace tacking with something?
 
no, literally type in tracking
 
oh ok
 
that means whenever you type "git push" it will push your current checked out branch to exactly the branch that is shown that it is tracking
and not try to do anything else
 
alright, thank you very much
 
7:45 AM
which is normally what people want, which is why it is so confusing that it isn't the default (to me anyway)
good luck with it!
 
and I'll update thew git version
 

last day (14 days later) »