I am very new to github. I was trying to pull a branch from a repository which contains some php code.
I used git clone <url>
then I used git checkout <branchname> to switch to a specific branch.
Since I am using Github for Windows, the files are stored in Github folder of My Documents. Now I want to test the code and make some changes to it in my localserver. So should I copy paste the project folder in the www directory of my wamp folder? Or should I do something else? And if after copying the folder, if I want to commit any changes, what command should I use to push?
Github for Windows does mention in the help page that:
GitHub for Windows is optimized to work with GitHub remotes — but if you wish to use a non-GitHub remote, it will work just fine. Set the remote manually in the settings tab and everything else should work as expected. You can also drag in repositories from the file system and GitHub for Windows will respect the configuration of the origin remote.
So you can pull from a non-GitHub repo, like I did in this answer or as illustrated in this blog post.
But from your local clone, you cannot easily push to another repo (like one in your wamp folder for instance)
it does not support multiple Git remotes and it will only work with the origin remote.
If you wish to push & pull to other remotes, we suggest you use the command line client that is included with the application.
An alternative to command-line would be to use a GUI which does support multiple remote, like SourceTree.
Or you can clone the GitHub repo from the command-line directly in the right folder, and then declare that local repo in your GitHub for Windows app.
Or you could create a virtual host that has a DocumentRoot of the Github folder of My Documents (meaning you don't have to move anything, and can keep using GitHub for Windows as you were).
Related
I created a folder on OneDrive called My files>GitHub>MedAverter. I note it's url:
https://onedrive.live.com/?id=CC97284F14BADC27%211034825&cid=CC97284F14BADC27
I downloaded GitHub Desktop and set the Current repository to the newly created MedAverter folder.
I navigate to my local code folder in git bash:
/c/users/greg/LaravelProjects/MedAverter
I enter the following command:
git remote set-url origin https://onedrive.live.com/?id=CC97284F14BADC27%211034824&cid=CC97284F14BADC27
To check it is correct, I do:
git remote -v
here is the output:
origin https://onedrive.live.com/?id=CC97284F14BADC27%211034824 (fetch)
origin https://onedrive.live.com/?id=CC97284F14BADC27%211034824 (push)
Note that it is shorter than the original?
I do a git status and see a bunch of unstaged files, as expected. I stage them with
git add .
Then I commit the files with:
git commit -m "first commit"
Then push the files with:
git push -u origin master
But get error:
fatal:
https://onedrive.live.com/?id=CC97284F14BADC27%211034824/info/refs not
valid: is this a git repository?
What am I missing?
In order to use an HTTP remote for Git, it either has to support the smart protocol, which requires a special server endpoint, or it has to support WebDAV, which is commonly referred to as the dumb protocol. In addition, the remote cannot use query parameters, since Git will not handle them.
If you want to use OneDrive with WebDAV, you'll need some way to get the initial repository structure up to the server, which will likely involve using a standard WebDAV client to upload a directory created with git init --bare.
As mentioned, you'll also need a WebDAV URL that doesn't include any query parameters; if OneDrive can't provide that, then you'd need to use a different provider.
Do note that you should not use OneDrive as a syncing tool for your Git repository across machines because doing so can cause corruption.
I strongly suggest that you do not use OneDrive shared folders to host a git repository you are working on locally whether you are syncing across machines or not.
One Drive has some challenges keeping a proper sync when files are deleted, and this can cause havoc on your working directory.
As of October 2022, this issue has not been resolved and I've been burned by it in the past.
Example:
Refactoring your code (or changing branches/commits) can result in files that need to be removed from your project. OneDrive doesn't always recognize the local file deletions and so it will synchronize the files back and whole folders/files can re-appear whenever this happens.
The working directly may then be polluted with folder/file additions that you did not intend and can cause havoc.
Bottom Line: Git is the tool to manage your working directory related to repo and collaboration. Backups need to be managed with the git repository stores itself, and do yourself a favour and don't mix OneDrive and Local repos or working directories
Here is a link with a "fix" that isn't a fix for this use case but explains the issue in better detail for reference:
https://www.urtech.ca/2021/01/solved-files-synced-to-onedrive-keep-reappearing-after-deletion/
I'm new to using Github and I'm trying to get my PHP project in Netbeans to work with Github.
I created a new PHP project from existing sources with the source folder as my network drive which is also being used as the FTP location for my web server. I saved the metadata to my local drive. The git files location is on my local drive with my metadata.
I was able to create initialize repository without any problems but when I try to push my project up to my git repo it shows no local branches I can select.
What am I missing or doing wrong? Thanks for the help!
I was able to create initialize repository
Once the repo is created, you need to add and make an initial commit, in order for a branch (master) to be created.
Then you would be able to select said master branch in order to push.
I know this has been asked before, but I couldn't get the answer I needed.
Currently I'm developing an website using PHP and was using Notepad++ before, and it all worked well because I'm developing with a co-worker so we both keep on changing different files on the FTP.
Switched to NetBeans. All went ok, pulled the entire website via FTP to my local computer and everytime I edited a file and saved it uploaded to the FTP. But, there is a problem. If my colleague updates a file, it doesn't update on my local folder. So, I thought: "Let's try versioning".
Created a team on bitbucket, created a repository. All went ok.
But now, I'm in a struggle to get everything up and running on both NetBeans (mine and colleague's) so that my colleague is editing a file on his NetBeans and constantly saving so that it gets saved on FTP and only when he stops working on that file push it to BitBucket so that I can pull after.
Suggestions?
About setting up your work environment :
In order to set up your bitbucket repository and local clone, go read this link (official doc).
You will need to repeat the cloning part once for each PC (e.g : once on yours, once on your colleague's).
Read the account management part to see how you can tag your actions with your account, and your colleague's action with his own account.
Start using your git workflow ; when you are tired of always typing your password to upload modifications to your bitbucket account, take the time to read the ssh keys setup part - read carefully, you will need to execute the procedure once for you and once for your colleague.
Using your local git repository with Netbeans is pretty straightforward :
From netbeans, run the File > New Project ... command (default: Ctrl+Shift+N),
Select PHP application with Existing Sources and click Next >,
For the Sources Folder: line, select your local git directory,
Fill the remaining fields, and if you want the last Run configuration screen, then click Finish.
After the project is created in netbeans, you can modify the Run configuration part by right clicking on the project's icon, selecting the Properties menu entry, and going to the Run configuration item.
About solving your workflow "problem" :
Your current FTP workflow can lead you to blindly squash your colleague's modifications (when uploading), or have your colleague's modification blindly squash your own local modifications (when downloading). This is bad, and you will generally notice it only after the bad stuff happened - too late.
Correctly using version control allows you to be warned when this could potentially happen, and to keep an almost infinite undo stack on the modifications of the project's files. The cost, however, is that both of you will have to add several actions in your day to day workflow - some choices can not be made automatically.
You may find it cumbersome in the beginning, but it really pays off, and quite quickly - we're talking big bucks here. So use it and learn.
On top of using Ctrl+S to save your modifications on disk, you and your colleague will need to integrate 3 extra commands in your daily work :
Save your work to your local repository (git add / git commit)
Download the latest modifications shared by your colleague (git pull)
Upload your work to the central repository (git push)
You can access these commands :
from a terminal,
from a GUI frontend : you can try TortoiseGit for windows, or gitk for linux,
from Netbeans :
in the contextual menu of the files/folders in the project tree (right click on the item, there is a "Git" entry),
using the Team > Git > ... menu
Since you provided a git tag, I'll describe what's to do for Git.
set up a remote bare repo on a server that you both could access (BitBucket in your case):
http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server
you both clone that remote repo to your local machines:
http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository#Cloning-an-Existing-Repository
each of you works in her part of the application. When one is done, publish the work to the server:
http://git-scm.com/book/en/Git-Basics-Working-with-Remotes#Pushing-to-Your-Remotes
By now, the remote server holds the version that was just pushed. What's missing is the deployment of the website. This has been discussed here:
Using GIT to deploy website
Doing so, you will decouple your work from that of your colleague since you're not changing files over FTP all the time. You work in your part, your partner works on her part. The work is getting merged and then a new version of the website gets published.
You can create git or Mercurial repositories in Atlassian Bitbucket (http://bitbucket.org). If your team is new to version control, i advise you no forks in your first project.
The easy solution ins to use Atlassian SourceTree (http://www.sourcetreeapp.com/) to control your code since there is a bug in netbeans. See NetBeans + Git on BitBucket
You need to create a new repository in bitbucket. I assume you already configure the ssh2 keys. Using Git you need:
git clone --bare --shared php_project php_project.git
git commit
Using Mercurial you need:
hg init
hg commit
Good luck / boa sorte
Pedro
I am new to GitHub. I managed to install GitHub for Windows and created a github repository. I'm a PHP developer and this is my current situation before GitHub.
Currently, all of my work go to C:\xampp\Dropbox\* ("htdocs"). Everything I code is in there with each application under its own subdirectory. Whenever I need to update the production server, I FTP our production server and upload the necessary files. This is good when I am working alone but working with other developers would be hard because we need to know who edited which, when what was edited, etc.
Could you help explain how I can maintain my codes using GitHub? I suppose that I shouldn't make the entire htdocs as a local repository. I access my codes via http://localhost/ when testing it locally. Since I develop web applications using PHP, code changes regularly. We don't compile codes and I was used to simply saving all the files and letting Dropbox save all the versions I made.
It's a bit confusing what to do next since the GitHub for Windows application created local repositories in C:\Users\Admin\Documents\GitHub\test-app folder. Should I edit the code in htdocs and ALSO edit the code in My Documents\GitHub? Then also "push" the update to GitHub AND also update our production server via FTP?
So, to summarize, from the primitive perspective of web development, what steps must be changed so that I can enjoy the benefits of using version control systems such as GitHub?
Thank you!
The global idea is to use a versioning server to push code directly into your production server, bypassing FTP boring method.
You can tell GitHub application to clone your code at Xampp htdocs root, instead cloning it into your documents, if you have already initialized your repositories.
Every project must be a GitHub (or Git, more generally) repository.
So, you have to :
git init all your projects into your local server, at root of your project (so, not htdocs, but htdocs\<YOURPROJECT>
create repositories on GitHub for each of your projects
Follow GitHub instructions to initialize projects, git push on GitHub to finish.
You can do all that with a command line. In my opinion, it's easier.
Your code is on GitHub now. You won't have to edit your code into your documents AND htdocs if you initialize your repos in htdocs.
Next, it could be "fun" to install Git on your production server to grab most recent code from GitHub repository. Without Git, it's a pain in the a** to push code on a production server.
Now, when your local dev server and your production server are in sync, every time you will commit and push on GitHub, you can grab latest copy with a simple git pull on your production server.
I am using openshift server to host my php application. I have added files to my server using sftp to ~/app-root/runtime/repo directory. The same files are accesible over the web. But when I git clone my repository to my local machine I don't see my uploaded files in it. Neither when I add and push files using git are seen in my app-root folder. Any help is kindly appreciated
Changes made directly on the gear's repo/ dir are not tracked by git, and will be overwritten when you push your local git repo to the gear. To track them, scp/sftp them back to your local git repo and add/commit/push them across.
The alternative to scp/sftp is to run "rhc snapshot {appName}" which will take a backup of all your files (code and data in case of snapshot), then you can extract the files under the repo/ dir back to your local git repo, and add/commit/push them across.
Feel free to post to our forums: https://openshift.redhat.com/community/forums/openshift