I have created a git repository of a linux directory and pushed all files into it. I have recently moved a new file into that linux directory and now want to push this new file into its git repository. I am trying to do so by typing
git push origin master
in the command line but I am getting the errors:
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Does anyone know how to push a new file into an existing git repo of the folder in which the file is present? I am new to git so would appreciate suggestions.
If your file is already in the git repo you have created, adding and committing are enough: no need to push.
myrepo <== "I have created a git repository of a linux directory"
.git (the .git folder is the git repo referential)
myNewfile <== "I have recently moved a new file into that linux directory"
Ie. there is no remote 'origin' to push to for a local git repo.
The chapter "Git Basics - Recording Changes to the Repository" is the good place to start.
git add myNewFile
git commit -m "Add a new file"
Validate if you have the repository branch (on which you are working) checkedout.
Make sure you pull the updates first
Do 'git add newfileNameWithPath' and commit before you push it.
It seems you have a wrong understanding about git push command, please read the following figure, which will give you a more clean concept.
Related
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'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
I am trying to clone my a git repository inside an existing checked out git repository and getting this failure. I've done this workflow before so I cannot figure out why it would fail now. Does anyone have any suggestions?
The git repository does exist and I can clone outside of the checked out repository in a different location
Let's say I do the following
1. cd <existing git repo clone folder>
2. git clone https://github.com/apache/cassandra
Cloning Git Repository of cassandra
Cloning into 'cassandra'...
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
What could be causing this error?
PLEASE NOTE - I DO NOT WANT TO ADD THIS REPOSITORY AS A SUBMODULE TO MY PARENT GIT REPO. I simply want to figure out how to clone the repository in an existing working folder checked out from git.
Have a look at git submodules This was designed exactly for this. You can find information and examples here: https://git-scm.com/book/en/v2/Git-Tools-Submodules
In your case, this might work:
git submodule add https://github.com/apache/cassandra
In order to change the submodule to track a particular commit change directory to the submodule folder and switch branches as normal.
cd submodule
git checkout -b some_branch origin/some_branch
or for some particular tag
git checkout <version_tag>
You will need to commit this change to update.
Your question sort of seems to be in conflict. You can't have a git repo within another git repo without using git submodules AFAIK.
What you could do is have a dir that is not a git repo, and clone both the repos into that dir (so don't put the repos inside each other).
You could also add the repository as a remote (using git remote add name_of_remote http://your/remote/here). Then you can checkout any branch from either repo in the same repository.
I usually do not like to use submodules. for this case I would do the following:
1) in the main repo .gitignore the folder path where you want to store the repo the path-of-cassandra-repo/* (to ignore it)
2) in the terminal execute git clone https://github.com/apache/cassandra.git path-of-cassandra-repo/ where "path-of-cassandra-repo/" the name of the folder you want git to store the repo.
3) you are ready to go... Happy coding.
Let me know if this works for you...
I've just installed git on Ubuntu, now I want to work on my repo in BitBucket. I'm a little confused on how to do so. I can't do the following:
git remote add BitBucketRepo git#bitbucket.org:dir/file.git
As it returns the following error:
fatal: Not a git repository (or any of the parent directories): .git
It clearly is pointing to a git repo, so why is it lying to me?
Also, it is worth noting I am using SSH and I have successfully paired my GitHub account to my computer.
You need to run this command from a local git repository (a directory in which you have run git init or git clone) - otherwise git remote doesn't know which local repo you want to add the remote for.
It should be as simple as cd my-local-dir, where my-local-dir is the directory containing your local (cloned) git repository.
If you don't yet have the repo available locally:
git clone git#github.com:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo git#bitbucket.org...
git push -u ButbucketRepo master
This will clone your code from Github into the my-local-dir directory, add your BitBucket repo as a remote repository, push your code up to Bitbucket and set the local master branch to track the BitBucket remote's master branch.
Tracking means that commands that involve a remote like git push will automatically use the BitBucket remote's master branch. If you don't want that behaviour, skip the -u option.
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.