To deploy my Laravel app to my server, I decided to just download the zip file and unzip it in the folder.
However, I made some changes on my server and I would like to push them to GitHub.
Since there is no .git folder, I don't get how am I supposed to commit the changes or pull from the repository.
Can you help me ?
If you have a repo already that has commits do:
git clone git#REPO_LOCATION_INFO
Check out a new branch on your local:
git checkout -b branch-name
Make your changes, save, add, commit, and push them:
git add .
git commit -m "My commit message"
git push origin branch-name
then open a pull/merge request in your repository and merge to master.
Otherwise you can remote the folder on your local to your repository with:
git remote add origin git#github.com:user/repo_name
and then commit like shown above.
Hope this helps!
I've successfully done that following way:
Rename repo zip downloaded (without .git)
mv repo repo-bak
Clone original repo
git clone <url>
move .git file to zip downloaded repo
mv repo/.git repo-bak
delete cloned repo
rm -rf repo
change the name back to the original
mv repo-bak repo
add, commit and do whatever you want
cd repo && git status
Related
Suppose I have a git repo named waterkingdom It has lot of branches. We will be working with a specific branch called wave-pool.
wave-pool branch has files & folders such as
cost.txt
ride.txt
rules.txt
code/
code/ride.py
code/boom/crash.py
We have another folder which is not a part of the repo named wave-pool-boom
How can I only sync the branch wave-pool from waterkingdom repo to the folder called wave-pool-boom after the commit without knowing the latest commit hash?
Everything is locally on Linux.
How can I only sync the branch wave-pool from waterkingdom repo to the folder called wave-pool-boom after the commit without knowing the latest commit hash??
Everything is locally on LINUX.
Pushing branches from one repo to another is easily done in git, and makes a lot of sense the more you work with git.
Clone waterkingdom into a new directory
git clone --single-branch -b wave-pool /path/to/waterkingdom ~/projects/waterkingdom
cd ~/projects/waterkingdom
Setup a new remote
git remote add r-wave-pool-boom /path/to/wave-pool-boom
Push the branch to the remote (but do not change its tracked remote branch)
git push r-wave-pool-boom wave-pool
Remove the remote (optional)
git remote remove r-wave-pool-boom
Tools to help you further your Git knowledge
git branch -avv
Gives a listing of all branches and what remote branch (if any) they track, what the latest commit hash/message is, and the state (behind, ahead) of each branch.
git remote -v
Give a listing of all the remotes (if any) and their URL's configured for your local repo.
Further comments
Why "without knowing the latest commit hash"? The latest commit hash is always HEAD or <branch-name> or refs/remotes/origin/<branch-name>.
I have to create 100 repos from my local filesystem. Each project directory has to be created as a separate repo.
I have created separate folders for each of my project and created a base repo on Github. I clone it to my local and tried to do push. However I got all these folders as folder on GitHub.
I need each folder to be a new repo.
Your script it such as, for each folder:
you call the GitHub API to create a new repository
you initialize a new empty repository in the current folder
git init .
git add .
git commit -m "first commit for folder x"`
you define the remote URL, and push
git remote add origin https://github.com/you/folderN
git push -u origin master
I have an xcode project on my desktop in a directory that originally had a git repository with a tracking branch that tracked a remote branch on github. The remote branch has some 84 commits and is 2 commits ahead of the master branch of the project I'm adding features to. I changed the name of the folder/directory on my desktop. I'm not 100% sure if this is the reason why but when I go to git status I get: fatal: Not a git repository (or any of the parent directories): .git. My plan is to simply git Init, add the remote branch and create a new tracking branch and than commit locally to that branch and than push to the remote branch. However, I'm a git beginner and I'm not sure if this is the proper way to go about it. I'm very weary of losing any commit history or accidentally breaking something. Is the method I outlined a good way of rectifying this loss of the git repo?
If you have all your code updated in remote repo then your local .git is deleted. You don't need to re-init your local repo. Rather just clone it.
git clone remote_repo
If you don't have any commit in remote repo, Simply follow
git init
git add all_local_files
If you have updated remote repo than some commits made in local but not pushed and you lost .git. Simply clone remote. Add all files in a single commit
git clone
git add all_local_files
Looks like you messed up your git repository, but not the code / contents.
One way to restore and keep local changes ( if any ) would be:
Clone another copy of your repo from github.
Copy all modified files to the new repo, omitting removed ones: rsync -duztv /old/local/repo/ /new/local/repo
git status to see what the situation is.
I am new in git and want to push some java files to remote github repository. The files are NOT a project, just some algorithm problems that I want to share on github.
When I tried git push the alert fatal: not a git repository: .git
Is there any quick way to push some/single file to repo using git bash? thanks
One solution would be to do a git init . in the folder whare your files are.
Then add the github repo as a remote:
git remote add origin https://<yourLogin>#github.com/<yourLogin>/<yourRepo>
git add .
git commit -m "My first files"
git push -u origin master
The other approach, especially if the remote repo on GitHub is not empty (because of README and LICENSE files), is to clone that repo:
git clone https://github.com/<yourLogin>/<yourRepo>
cd <yourRepo>
# copy your files there
git add .
git commit -m "My first files"
git push -u origin master
so I just installed a new remote git repository on one of our servers and want to move our old projects there. Our existing projects have local git repositories, and we can add repos from the server, but how do we move our existing projects onto the server?
Any ideas?
You would do these steps:
Make the individual repositories on the server.
git clone --bare nameofrepo
On the actual repo, add the remote to the repository from which you want to send up work:
git remote add origin <url to your remote>
Now push your branch for your work:
git push origin master
Repeat for any other branches you want to have pushed to the central repo.
The URL in the first command can also be a regular file path. Most solutions, however are through an SSH connection.
After creating your Xcode project, cd to that directory
and make sure you are on the master branch
Type:
git remote add origin <URL-of-your-GitHub-repository>
git pull
git branch --set-upstream-to=origin/master master
git merge
git commit -m "Merging with remoteā
git push
Now your new project has been pushed to the remote GitHub directory.