Syncing remote and local failure - github

I am a noobie to terminal programming. I'm trying to delete a subfolder from a repository. The path is as follows:
CMSC764-Advanced-Numerical-Optimization/Homework-3/
This has two subfolders - MATLAB and Python and I want to delete the MATLAB one. I tried this: git rm -r *.m and this deleted the files locally. When I run ls , the MATLAB folder doesn't show.
I tried to commit the changes by git push origin master and it says Everything up-to-date but the MATLAB folder continues to exist on the remote.
There are several variations of these commits online and it's a lil puzzling.

Committing is not "git push", but git commit:
git commit -m "delete files"
That will commit the index state, index which should reflect the git rm you did.
Then:
git push -u origin master

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.

How to upload all folder to github?

I have created a repository on github, and run the command line git push -u origin master. I just find a folder over there, but I have a lot of file in my folder, but it only uploaded a folder that has no files in it.
How do I upload a folder with lots of files successfully?
I just tried the command git add . and git push -u origin master
It's not working.
Please me teach me what step I missed. Thanks in advance.
You need to add all of the files in the folder. If you actually want to add all of it (not just some), an easy way to do that would be git add -a or git add ReduxSimpleStarter/*.
Then you need to commit them. git commit.
Then push.
I'm guessing, by your description (sorry, it's a bit hard to read. So correct me if I am missing some details to your problem) you're forgetting to commit the changes.
To do this you need to git commit -m "A commit message". It would look something like this all together
git add .
git commit -m "Added a new button"
git push -u origin master
commit just tells git to save the changes you made to it's history. add just tells git that you want those files (in their current state) to be saved next time you commit.
Hopefully that solves your problem.
It looks like you are not committing your changes before pushing.
When you do this:
git add .
your files are adding to the staging area. But you also need to commit them. You can do this by typing this into you command line after doing the 'git add .' command:
git commit -m "your commit message here"
Then you should be able to type 'git push -u origin master' and your files should upload.

How to push and clone yii2 projects to 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

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).

github uploading project issue

I created a github new repository first in github webpage and then I opened Git Bash to upload folders to this repository. I first used $cd f: and $ git clone git#github.com:username/project name.git to create a folder(with a initial .git folder and a README file in it) in f disk. Then, I used $cd f:\project name to switch to the current folder. After that, I copied all my project folders to my project name folder in f disk. Finally, I used the following four lines to upload all my project folders to github:
$git add .
$git remote rm origin
$git remote add origin git#github.com:username/project name.git
$git push -u origin master
After I entered the passphrase, Git Bash just showed everything up-to-date. But I refreshed my github repository page, there is nothing but the initial README file. Could someone tell me what the matter is?
You didn't commit after your git add.
git commit -m "first commit"
That is why git considered there was nothing to push: you HEAD was still the same than your remote origin cloned repo.
See Git Basics:
Your git add updating the staging area (index), but only a git commit will update your git directory.