First of all, I am a noob at using git.
I was working on a project and did a commit and pushed to remote github repository.
But, then later I realized that I did some mistake, so I did $git --amend -am "My message"
Now, I was not able to push again to the remote server as I was getting error. So, I thought of deleting the remote github repo & recreated the same with the same name.
Now, when I try to push, it says "Everything up-to-date".
Please guide as to how do I solve this?
Sounds like two things have gone wrong, here.
First up, you amended a commit that had become part of the remote repository's history, which is a bit of a no-no. Rather than re-answer this gripe, I'll direct you to the answer: How do I push amended commit to the remote Git repository?
Next, chances are that even though you re-created the remote repository, your local repository still has the local history from the old one. what you'll want to do is run git remote rm origin, then git gc, then git remote add origin <path_to_repo>, then finally git fetch origin. This should pick up the new remote repository, and allow you to push your changes to it.
Related
I was trying to upload a file via terminal.I am trying to learn git.
**
git add /Users/serra/Documents/useSDWebImage
git commit -m "learning on process"
git remote add origin
git push -u origin master
**
then I got this message error: failed to push some refs to ....
I tried those commands then I have only the file I want to upload
to repository I have lost rest of the repository.What should I do?
**
git pull --rebase origin main
git push origin main
git pull origin master
git push origin master
git push origin master --force
**
TL;DR
You need to find a backup, somewhere, of origin/master.
git reflog might help you.
The error
First, let's go over your first four commands and explain what the mistake was.
In the first two commands, a git add and git commit, you are creating a commit in your local sandbox, building on whatever was in your sandbox beforehand.
In the third command, you add your remote, which means that your commit was not made on top of that remote, but on top of something else.
In your fourth command, Git correctly tells you that you cannot push, because your local sandbox is not built on top of the remote. It's important to pay attention to Git's error messages, they're almost always informative.
Now, you're not showing outputs from any of the commands you ran, but I'm guessing git push origin master --force is what deleted stuff on your remote.
What you should have done
Normally, you clone the remote first, then commit stuff on top of it:
git clone <URL>
cd <SANDBOX_DIR>
git add <file inside this directory>
git commit
git push
How to fix this
There are several ways, but they're all based on recovering stuff from a backup that hopefully exists somewhere.
If your remote is GitHub, it keeps a history of references, you should be able to find that old master branch somehow there. If your remote is some other server, that is hopefully true too. If another team member has a sandbox that had the valid master you want to restore, they can fix things by doing a git push origin master --force in their own sandbox, but make sure they understand what they're doing before they do it.
My answer here is not complete, because you didn't provide enough information. I will update it if you update your question with more details about your remote.
Update - git reflog might help
When you did git pull origin master, assuming master is the branch you care about, you probably got a local copy of the correct master commit you want on origin. You can use git reflog to see the history of your local HEAD in your sandbox. If you find the good commit there, this solution could work:
Here I'm assuming these is not work you want to preserve in your sandbox.
git checkout master
git reset --hard <good commit> # WARNING: destroys any uncommitted local changes
At this point, check that your sandbox contains the files you want to restore to origin. If so, proceed with this command:
git push --force origin master
But be warned, this will overwrite what's on origin. It's only appropriate if you have carefully validated that master in your sandbox really contains the history you want to restore on origin.
i'm trying to push a local project to a gitlab repository. I followed the usual commands provided with each new Project. Everything worked just fine until the last command; I acctually dicovered the local project is being pushed to a gitlab project that I actually deleted.
And each time I create a new project and try to push to it, the files are directed to the one I deleted but is somehow re-created with every push.
Any thoughts?
Try reading the following guide. Although is for github, is almost identical for gitlab. (understanding git is the key). I think you need to re-formulate your question better:
You have the following remote: origin with path https://<your-gitlab-project-repo-path>.git. Then locally, you run:
cd your-project
git init .
git remote add origin https://<your-gitlab-project-repo-path>.git
git add .
git commit -m "initial commit"
git push origin master
Done.
I am developing a project on my laptop that is to be implemented on my VPS. I am continually making updates on my laptop and pushing them to my git repo, but I am in the dark on how I should keep the clone I made on my server, updated.
When I try to run git clone <url> in my directory, it tells me 'file already exists!' or something along those lines. Do I just delete the entire folder and reclone the repo like that? Or is there a way, other than initiating the directory as git, and creating an upstream, that I can reclone without having to delete everything first?
How do I keep a git clone updated?
I generally clone git project.
git clone git#source.golabs.io:mobile/project-name.git
and after that I start developing my feature by creating new branch branch.
so for up to date with remote project you need to checkout to master branch. and just do
git pull and sync your project using ./gradlew clean build
If your project have submodules- you need to do
git submodule update --init --remote --recursive
try to use git pull. it will automaticly analyze the difference .And try to fix it
Instead of having to go to your server and pulling, you could setup a listener in order to do the pull for you.
For instance, if you are ushing to GitHub or BitBucket or GitLab, you can setup a webhook (GitHub webhook, BitBucket webhook, GitLab webhook), and a local listener in order detect the push, and triggger a git -C /path/to/your/repo pull.
I'm relatively new to the whole github thing. So, I deleted a repo from my github and then I'm to re commit on a new repo I created but it still recognizes the old repo it was linked to, so each time I say commit, it keeps saying "There's nothing to commit" meanwhile, the github page that's linked to the repo gives a 404 which is because the repo its linked to was deleted however the CLI still recognizes it, is there a way I can fix this.
The aim is to start afresh, like, since I have deleted the repo on Github, I want to re create it, recommit, etc but it seems the past history is still being recognized.
You can change your local clone to work with the new repository. For that first remove the link to the old repo,
$ git remote remove origin
and then add the new repository,
$ git remote add origin -f <repo url>
The easiest way to start over with your new repo is
git clone <URL for your new repo>
First of all, a quick clarification
A commit is local to your project, so indeed making a new commit is pointless, even if you have deleted your old remote repository.
A push is effective on the server side, so I suppose this is where you will have some trouble with your new remote Github project, like a "fatal: repository not found".
So you have two options :
1) You start by cloning your new repository with :
git clone https://github.com/your_username/your_project.git.
And then you will be able to commit and then push but you will have to move your source code to this project.
2) If you want to keep your old "still linked" project, I'd effectively suggest to start fresh by removing your local .git folder, initialize a new one and then make a commit and a push to your new Github project.
Something like :
rm -rf .git
git init
git remote add origin https://github.com/your_username/your_project.git
git add .
git commit -m "first commit"
git push origin master
First off, forgive me if this is a duplicate question. I don't know anything but the basic terminology, and it's difficult to find an answer just using laymen's terms.
I made a project, and I made a repository on Github. I've been able to work with that and upload stuff to it for some time, on Windows. The Github Windows application is nice, but I wish there was a GUI for the Linux git.
I want to be able to download the source for this project, and be able to edit it on my Linux machine, and be able to do git commit -m 'durrhurr' and have it upload it to the master repository.
Forgive me if you've already done most of this:
The first step is to set up your ssh keys if you are trying to go through ssh, if you are going through https you can skip this step. Detailed instructions are provided at https://help.github.com/articles/generating-ssh-keys
The next step is to make a local clone of the repository. Using the command line it will be git clone <url> The url you should be able to find on your github page.
After that you should be able to commit and push over the command line using git commit -am "commit message" and git push
You can use SmartGit for a GUI for git on Linux: http://www.syntevo.com/smartgit/index.html
But learning git first on the command line is generally a good idea:
Below are some basic examples assuming you are only working from the master branch:
Example for starting a local repo based on what you have from github:
git clone https://github.com/sampson-chen/sack.git
To see the status of the repo, do:
git status
Example for syncing your local repo to more recent changes on github:
git pull
Example for adding new or modified files to a "stage" for commit
git add /path/file1 /path/file2
Think of the stage as the files that you explicitly tell git to keep track of for revision control. git will see the all the files in the repo (and changes to tracked files), but it will only do work on the files that you add to a stage to be committed.
Example for committing the files in your "stage"
git commit
Example for pushing your local repo (whatever you have committed to your local repo) to github
git push
What you need to do is clone your git repository. From terminal cd to the directory you want the project in and do
git clone https://github.com/[username]/[repository].git
Remember not to use sudo as you will mess up the remote permissions.
You then need to commit any changes locally, i.e your git commit -m and then you can do.
git push
This will update the remote repository.
Lastly if you need to update your local project cd to the required directory and then:
git pull
To start working on the project in linux, clone the repo to linux machine. Add the ssh public key to github. Add your username and email to git-config.
For GUI you can use gitg.
PS : Get used to git cli, It is worth to spend time on it.