How to push and clone yii2 projects to github? - github

I have developed a simple web-app with yii2 and pushed it to my github repository. I tried to clone it to another folder and test it, but it didn't work.
Something tells me that it is because I get my yii2 from an archive without composer and when I try to clone it, I use composer install command to get vendor folder and autoload file and it doesn't do it right.
Why is it happening and how can I push my web-apps properly to github so that everyone can clone and start them? Thanks in advance.

Once you've done the Yii2 app ready into you local, kindly follow below basic commands of Git.
Git Basic Commands
Git Checkout:
$ git clone CHECKOUT_URL
To check git files status:
$ git status
To add all file into git:
$ git add *
To add selected file into git:
$ git add filename1, filename2
To commit all added/updated/deleted files into Git:
$ git commit -m "initial commit" *
To commit selected file into git
$ git commit -m "initial commit" filename1, folder1
To push committed files into Git master branch:
$ git push -u origin master
To see all exists branches:
$ git branch
To create new branch:
$ git branch changes
To select branch:
$ git checkout changes
To commit into selected branch “changes”:
$ git push origin changes
Other Git Commands:
$ git --help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG

Related

How can I git push to a specific folder?

I'm using Travis CI to build my Jekyll site and push to Github. A lot of documentation around is for keeping the Jekyll code in the master branch, and building the site and pushing _site to the gh-pages branch. I want to avoid doing that and use the username.github.io repo on Github.
This is currently my build script:
#!/bin/bash
# skip if build is triggered by pull request
if [ $TRAVIS_PULL_REQUEST == "true" ]; then
echo "this is PR, exiting"
exit 0
fi
# enable error reporting to the console
set -e
# cleanup "_site"
rm -rf _site
mkdir _site
# build with Jekyll into "_site"
bundle exec jekyll build
# push
cd _site
git config user.email "john.doe#gmail.com"
git config user.name "John Doe"
git add --all
git commit -a -m "Travis #$TRAVIS_BUILD_NUMBER"
git push origin master
Of course, git push origin master as of now replaces the entire branch itself with the generated site. How do I generate the site and keep it within _site?
I am assuming you are running this script inside some folder. lets call that my_project.
Inside my_folder, when you run this script, it creates a _site folder.
Next you are doing cd _site. Dont do this.
Instead, remain at my_project folder and do the git config steps and others at this level.
So this will push all the stuff inside this my_project folder and the site will be inside the _site folder.
TL,DR:
Change these lines:
git add --all
git commit -a -m "Travis #$TRAVIS_BUILD_NUMBER"
To:
git add ./ #I assume you've cd'd into the directory you want to commit.
git commit -m "Travis #$TRAVIS_BUILD_NUMBER"
Explanation:
This question smells like a problem that someone coming from svn would have.(Skip the next paragraph if you aren't coming from svn)
There is a big difference in the way svn and git handle commits.
When you use svn, the commit always works relative to the current directory. So, the line cd _site changes what is known as the present working directory to _site. And there on out, svn only is concerned about the current directory and its children.
On the other hand, git commands will climb the directory path till they reach the root. So, when you are in _site and give a command with a --allor -a it will commit all the changes in the whole branch.
So, you replace --all with ./ in the add command which is just linux shorthand for the present directory. And remove the -a in the commit command. So the "changes added" are only from the present directory ie _site. This stages the changes for commit. You remove the -a from the commit command so that it only commits the staged changes.
As an aside, git add --all followed by git commit -a is redundant. The -a in commit ignores what is added to the stage and just commits all changes.

git(hub) lost all my changes in group project

I am working on an eclipse project with two friends. We use Git(Hub) to work as efficient as possible. Here is the problem: I worked on the project and uploaded the changes. Unfortunately, my friends were not able to see my modifications. Nevertheless, I was still able to see my new version in eclipse. Now I tried to upload it again but "there was nothing to upload".
Then I used git fetch and rebase to see if something would happen.
Unfortunately, all changes are gone now. I used git commit --amend and they "found a swap file by the name xx with the date of my last upload!".
Does anyone know how can I get back to my working version now?
If you didn't push your changes after messed up local history, then reset your local with remote.
$ git branch <branch-name> # backup the branch for safety
$ git fetch # sync with remote
$ git reset --hard origin/<branch-name> # reset local branch with remote branch
Alternate: git reflog will show you the whole git history you executed the commands. Copy the last working commit-hash you want to go back.
$ git reflog
Checkout to that commit.
$ git checkout <commit-hash>
$ git log # see the commit history
If all things are ok. Then checkout to a new branch. If you do any change in new branch then do Add, Commit and Push or, just Push to remote.
$ git checkout -b new-branch # create a new branch called 'new-branch' and checkout to that branch
$ git add .
$ git commit -m 'message'
$ git push origin HEAD # push to remote new-branch

git woes - when do a pull, it says its going to delete everything

Have an existing repo in git-hub with the projects files.
On a new machine, got into the target directory, e.g. myproject, and do this:
$ git init
$ git remote add origin https://github.com/myco/myproj.git
$ git pull (this downloads lots of files)
$ ls (no files)
$ git branch --set-upstream master origin/master
$ ls (no files)
$ git status ( shows all the files are marked for deletion! )
I have used this recipe before, no idea why doing a checkout of a repo causes it to delete all the repos files.
If I try and do the git branch before the git pull, it gives an error.
I cant use git clone, as ultimately, I need to have the files checked out into an eisting directory which already will have some project donfig files (not in git).
Any ideas?
If that is in fact the exact sequence of commands you followed, then here are some comments to help you understand where you are:
$ git init
Since it seems like you entered an empty directory (on a new machine, ...), this creates a new repository out of your current directory. This repository has no objects, no master branch yet, no commits, etc...
$ git remote add origin https://github.com/myco/myproj.git
This adds your origin repository and shouldn't be a problem.
$ git pull (this downloads lots of files)
This does two things - git fetch to collect all objects, branches, etc. that your origin repository currently has but your local repository doesn't (i.e. everything, since you're in a currently empty repository), followed by git merge. The merge phase should have failed here, with a message the the effect of "you didn't tell me what you want to merge, so I'm not going to do it".
$ ls (no files)
Right. You still haven't checked anything out, and since the git merge above failed, it never got to the point of updating your working directory.
$ git branch --set-upstream master origin/master
Now you are creating a master branch that has origin/master as its upstream, and as its starting point. However, this does not check out the branch, which leaves your working directory in the same state it was before, i.e. empty.
$ ls (no files)
You still have not checked anything out, so this is expected.
$ git status ( shows all the files are marked for deletion! )
git compares your empty working directory with what it thinks should be there, and determines that you must have removed everything.
What you really wanted to do there is this:
$ cd directory/where/you/want/your/repository
$ git clone https://github.com/myco/myproj.git
$ cd myproj
Then, copy your additional project config files into place.
If you really want to do it all the manual way, use git fetch instead of git pull, and after your git branch ... line, do a git checkout master (or do git checkout -b master origin/master in place of the git branch ... line, which implicitly does the branch setup before checking out the files).

push my project to github

I followed these steps: https://help.github.com/articles/generating-ssh-keys
now, I want to create a folder in my github account, is called: "TODO_LIST", and push my project into this folder.
what I should do? I'm located in the folder I want to add.
should I need to do something like the next following?
$ git init
$ git add .
$ git commit -m 'first import'
$ git remote add origin git#github.com:alonshmiel/TODO_LIST.git
$ git push origin master
p.s, I have two SSH keys in my account because I push from two computers.
This is explained in the Create a Repo help page:
Every time you make a commit with Git, it is stored in a repository (a.k.a. "repo"). To put your project up on GitHub, you'll need to have a GitHub repository for it to live in.
[...]
Click New Repository.
Fill out the information on this page. When you're done, click "Create Repository."
[...]
git init
# Sets up the necessary Git files
git add README
# Stages your README file, adding it to the list of files to be committed
git commit -m 'first commit'
# Commits your files, adding the message "first commit"
[...]
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repo
git push origin master
# Sends your commits in the "master" branch to GitHub

How do I commit a new project version on GitHub?

I'm new to GitHub and its terms confuse me a little. I made a commit. Now I want to change the project to a new refactored version.
Do I need to delete files from the existing repo before commiting new version (if the structure was changed and some of the files are not needed anymore)?
Do I need to push or to commit? Or do I need to do something else?
Making a commit updates the repo on your local machine. Doing a push will replicate your repo changes on a remote.
You can commit as many times as you want locally. Once you are happy with the state of your repo, you can update the repo on Github with the following command:
git push origin master
If you want to delete a file from the repo, you can do this:
# remove the file
git rm path/to/my_file
# commit the remove to your local repo
git commit -m "removing my_file"
# update the remote (Github) repo with the removed file
git push origin master
If the repo doesn't exist on Github yet, go ahead and create a repo there. They will give you step-by-step instructions on how to make your first commit. It will likely look something like this:
# go to project files
cd path/to/project
# initialize git repo
git init
# stage all project files in current directory to be committed
git add .
# make first commit
git commit -m "first commit"
# add the Github remote
git remote add origin <YOUR GITHUB URL>
# send repo to git
git push origin master
a commit to github is in two steps:
->first use command commit to save the changes localy
->then use push commande to save the changes on github