I am new in bitbucket.I want to upload project from Linux to bitbucket.successfully I have created a bitbucket account and did the following
1)create a repository name 'testadmin'
2)Using command line cd /var/www/myname/myprojectname
git init
git remote add origin https://username#bitbucket.org/user/testadmin.git
git pull origin master
then I get
Password for 'https://user#bitbucket.org':
From https://bitbucket.org/user/testadmin
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
But I didn't get my project from bitbucket.Please help me
ok, then
I would advice you to keep your project folder in www directly. Like if your project folder name is project_1 then it should be at var/www/html/project_1
then open terminal and reach to the folder project_1
cd /var/www/html/project_1 and then as you have already initiated git and added remote origin so you just need to push your code to repo.
To do so, follow these steps:
1) You need to add all the files to a commit bucket to upload on repo. For that,
git add -A (it will add all the files of the folder project_1)
2) Commit files with a message to track your uploaded work
git commit -m "First time uploading project 1" // The commit message will be for your reference.
3) Push the commited code now:
`git push origin master` // this command will push the code to master branch which is the default branch in a repo. You can create any branches on Bitbucket and add their name after origin to push to that particular branch.
After these 3 commands, check your repo. You should see your project up there.
Comment if you need further help.
Related
A large existing PHP project that is having Unit Tests retrofitted to it. I want to have a "tests" directory in the code on the development branch which contains these unit tests and perhaps the DB fixtures also. Naturally I don't want anything in there making its way onto the production environment so I want a way of automatically excluding this directory when it's deployed. Or ideally, a way to avoid anything in there that is committed from being merged into master in the first place.
How do I manage this? There will be frequent and unpredictable commits to the test directory so I can't simply skip certain commits manually.
EDIT: I've now got four answers telling me about .gitignore. I don't believe .gitignore is appropriate here because I want to exclude something that IS to be committed but only from a specific branch.
it's called .gitignore
From the docs:
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected
source: https://git-scm.com/docs/gitignore
For examples sake, let's say you have this working tree:
|-app
|-test
|-index.php
to exclude test/ the test directory add a .gitignore on the same level as the .git folder and in it just add:
test/
commit the git ignore and make a change/add a file to test/ and you'll notice it doesn't appear when you run
$ git status
You can use .gitignore. This is a file in your project root and you can list all files and directories you don't want to commit/push. They are separated by a new line.
I've found that the way to keep a part of a branch from being merged into another branch on a permanent basis is to use sub-modules.
I created my unit tests folder as its own repository and then included it in my mainline branch (which is not the production/master branch) as a sub-module.
https://git-scm.com/book/en/v2/Git-Tools-Submodules
By default when you clone a repository, sub-modules are not cloned with it. The sub-module directory is created but remains empty, unless you also execute
git submodule init
git submodule update
Therefore it's as simple as not including the above commands in your production git clone but including them when you clone the repository for testing or development. You can make any changes to the tests directory along with the codebase and commit both together. This means tests can be developed alongside the code base without risking them being deployed to production.
I found the following aliases useful to set up to streamline git operations:
$ git config alias.sdiff '!'"git diff && git submodule foreach 'git diff'"
$ git config alias.spush 'push --recurse-submodules=on-demand'
$ git config alias.supdate 'submodule update --remote --merge'
This seems to be the correct approach to solving the problem of wanting separation of code in a single repository to be different on a per-branch basis.
What I want to accomplish:
I have juts installed git on my development server.
I create a branch out of my 'develop' branch, work on my new feature branch, commit, and when I'm done - I merge the new feature branch with the 'develop' branch.
To apply the changes for the 'develop' branch on my development server I have to log in to my server and use git pull - which I'm trying to prevent and happen automatically - when there is something to pull from my development server - it will be done automatically.
I hope I'm clear about that I'm trying to accomplish ;)
What I have done up till now is:
Created a folder inside my project /www/hooks/ and added a file called post-merge: Following git documentation - this should get triggered whenever I merge a branch.
Inside this folder I added the text:
which should execute whatever is in between the backticks symbol ( ` ) as a shell command (following this PHP documentation)
Inside the folder /www/.git/hooks/ I added a symbolic-link to the file I previously mentioned with the same exact name: /www/hooks/post-merge :
sudo ln -s -f /www/hooks/post-merge /www/.git/hooks/post-merge
I gave the linked file under /www/.git/hooks/post-merge 775 file permission as the other files.
Some notes:
My repo is on Bitbucket
My directory /www/homepage/ is the one with the index file, so nothing can run outside of it on a browser (apache2 points to it..) - (but i guess there shouldn't be a problem since it's self executed via /.git/hooks ?)
I tried renaming both my files (the one under /www/.git/hooks/ & /www/hooks/) to post-merge.php and this didn't work.
just to have Carriage return
#!/bin/bash
git --git-dir "path/master/.git" --work-tree "path/master" pull origin master
you could try this in your post-merge
By accident i deleted PHP files with:
git clean -xfd
There is any good files recover tool for Windown PC to recover those files?
Or any other good solution?
Thanks!
wish its not late for this... but... if you didn't change the remote branch yet, you can make this:
git fetch --all // make you localrepo match with remoteRepo
(you can use -- if you want to fetch just 1 branch)
git reset --hard origin/<remote_branch>
With those commands you will have your local branch as the remote branch.
Example:
File = index.html
Remote branch(dev) = <html>... a lot of stuff ... </html>
Local Branch(dev) = <html><html><html><html>Bugged or deleted<html><html>
After git fetch --dev && git reset --hard origin/dev you local branch will be like the remote one.
I've been messing with this for like 2 days now and I'm not fully understanding the Git process yet and how I am supposed to deploy from github to production server.
Since it's a laravel website, what I did was first install a clean laravel installation on production, then added a git remote for the github repository. But when I try to do a git pull origin or git pull origin master, it keeps saying Already up-to-date.
Then I tried doing:
git checkout origin/master -b master2
But got the following error:
The following untracked working tree files would be overwritten by checkout:
_laravel/.env.example
_laravel/.gitattributes
_laravel/.gitignore
_laravel/app/Commands/Command.php
_laravel/app/Console/Commands/Inspire.php
_laravel/app/Console/Kernel.php
_laravel/app/Events/Event.php
_laravel/app/Exceptions/Handler.php
_laravel/app/Handlers/Commands/.gitkeep
_laravel/app/Handlers/Events/.gitkeep
_laravel/app/Http/Controllers/Controller.php
_laravel/app/Http/Controllers/WelcomeController.php
_laravel/app/Http/Kernel.php
_laravel/app/Http/Middleware/Authenticate.php
_laravel/app/Http/Middleware/RedirectIfAuthenticated.php
_laravel/app/Http/Middleware/VerifyCsrfToken.php
_laravel/app/Http/Requests/Request.php
_laravel/app/Http/routes.php
_laravel/app/Providers/AppServiceProvider.php
_laravel/app/Providers/BusServiceProvider.php
_laravel/app/Providers/ConfigServiceProvider.php
_laravel/app/Providers/EventServiceProvider.php
_laravel/app/Providers/RouteServiceProvider.php
So I guess I need to take everything from the repository and pull it to production server and force it to overwrite whatever is there now.
When you want to install an application on your server with git, you always start with making a clone of your repository into an empty folder. By adding a ., you can make a clone in your current directory. Otherwise, a new directory will be created.
You might decide to install your dependencies with composer on your production server. Then you make sure the vendormap is in your .gitignore. Then you can use composer install to load the dependencies, based on the composer-files you loaded with git.
i have some files and folder in my git repo. But some of them have a very long path that when i try to synchronize my workspace with git it gives me an error because windows cannot have characters in a path more than 260. Is there a way to pull specific files and folders? for example *.php files from /file/*.php?
I do not know much from git and also all other tutorials and answers i found here do not work. i even tried the git git_core.longpathenabled true but nothing happened.
Any ideas?
Is there a way to pull specific files and folders
Yes, you can use git filter-branch and or git subtree split
Sample code:
filter-branch
# Filter the master branch to your directory and remove empty commits
git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch
This will checkout all your desired files from the given folder to the current directory
subtree split
git subtree split -P <name-of-folder> -b <name-of-new-branch>
If your repository is hosted on Github or similar, you can download the file individually over HTTP, but you obviously will not be able to push changes.
Finally, if your copy of the repo is located in a deeply-nested folder you could move it somewhere like Users\You\Projects\cloned.