1

I've a project that I want to push to github, but I want to push it on the actual stage without any older commit. How can I do it?

Edit. I've created a separet branch for it, so I want to push this branch without any other commit from the other branchs. I'm doing this because I've added a late gitignore and now all files in the git ignore are being versioned and to the purpose of this branch/repository is to review the actual code of a few folders.

Big Boss
  • 250
  • 1
  • 3
  • 11

2 Answers2

0

Figure out the base of your branch:

git merge-base {baseBranch} HEAD

use a command to soft reset the branch back to before the first commit:

git reset --soft {hashOfCommitForYourBase}
git add .; git commit -m "my new message"

then push force:

git push --force
Daniel Leach
  • 5,517
  • 4
  • 18
  • 32
  • I'm using a separated branch, if I soft reset and move the head in the branch nothing will be changed on my main branch, right? – Big Boss Apr 07 '17 at 23:53
  • that's correct this command would only change the branch that you are working on – Daniel Leach Apr 08 '17 at 00:07
  • I'm getting an error saying there is no hash in the working tree if I use the hash given by the rev-list command, and if I use the first hash of the current branch nothing changes. – Big Boss Apr 08 '17 at 00:49
  • tested this idea a bit and problem was we were trying to reset before history began instead of a merge base commit. I edited it to use a merge base. You're going to want to use a commit that's a merge base for your eventual target. – Daniel Leach Apr 08 '17 at 01:18
0

After a little research, I found this answer, where the author suggest to use the command git checkout --orphan, and that was exactly what I was looking for, with this command I could create a new branch, with no trace of history of the other branchs, this way I could push to the repository with only the files I needed to show.

I just did this steps:

// Created a new orphan branch
git commit --orphan <branchname>

// at this point I have edited all my files, and set the .gitignore
// cleared cached files, so I have no issues with .gitignore files
git rm --cached -r -f .

// added all files
git add .

// commited the changes
git commit -m 'new orphan branch'

// pushed to the repository
git push <repositoryname> <localbranchname>
Community
  • 1
  • 1
Big Boss
  • 250
  • 1
  • 3
  • 11