How do I commit a new project version on GitHub? - 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

Related

Git Push "everything up to date" but file on github not change

after i learn to commit a file to github. now i have try to update file on github
by run syntax
git push -u origin main
and output message
Everything up-to-date
Branch 'main' set up to track remote branch 'main' from 'origin'.
when i check again on github the file that i was push no change at all
here my local file
please help me, im new to github
Have you committed first? With git, you need to commit your changes first, which is like saving each version locally. Then, when you push, you are publishing all of your versions to the remote (github).
Try the following:
git status
if it tells you about untracked files, use:
git add <filepath>
then:
git commit -m "<some commit message>"
This will save your changes as a commit locally, and you can now push this commit to github with the push command you used earlier.

Pushing folder into github

I was trying to push the folder on my computer to GitHub. So I created a GitHub repository, and use git bash command line. I didn't push the folder successfully on my first try. Then, I deleted the old GitHub repository and created a new one, and tried using the git bash command line to push code again. However, it shows nothing to commit.
Here is an image to better help understand
According to the image, I understand that you have made a commit but your commit was empty and you did not track any file with git beforehand. You typically want to track the files you want to commit. So in this case you could use git add before committing:
git add .
This should track all files in the current folder after which you could commit and push them:
git commit -m "Some message"
git push
When you create a new repository on git, it shows you how to properly upload data
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/youracc/your.git
git push -u origin main

How to delete GitHub blame history?

I'd like to delete the GitHub blame history that GitHub shows (tracking all changes made)
I am aware of how to how to roll back changes, but I am not trying to roll back any changes I have made, I am simply trying to delete this history of the changes.
Obviously, I do own the repository that I will be operating on (and am the sole owner)
If this is for all files of your GitHub repository, the simplest way would be to:
initialize a new local repository
add files from the original repo
add as remote the original repo GitHub URL
force push
That is:
git clone https://github.com/me/myrepo
git init myrepo2
cd repo2
git --work-tree=../myrepo add .
git checkout # -- .
git commit -m "Import myrepo"
git remote add origin https://github.com/me/myrepo
git push --force -u origin master

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

cannot see committed changes in repo

I have staged my files like this
git add mydir
git add mydir/myfile
and then pushed them to my repo
git remote add origin https://github.com/usename/myrepo.git
git push origin master
When I look at git status -s it says my files have been added, but I cannot see them in my actual repository. Does anyone know whats going on here?
You have not "added" your files to the repository, only to the staging index.
You need to git commit to get your changes from the staging index to the repository.
git status shows you the status of the working tree and staging index. git log shows you the status of the history - in other words, git log will show you what's been committed to the repository.
As an example, see this git status output:
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: Game.py
#
In this case, we can see that the changes to be committed involve Game.py. Note that these changes haven't yet been added to the repository - they're just staged, ready to be committed, as the git status says.
The next step is to commit these changes we've prepared in the staging index and add them to the repository. git commit is the command to do this.
This answer, as well as the linked Pro Git book, have some excellent reading which will help you understand the setup and steps in committing to a git repository.
I cannot see them in my actual repository.
What do you mean by "actual" repository? I am presuming you mean you can't see a local commit, but there may be some confusion about the repositories you're using.
You're using two repositories, one local and one remote. The remote repository is, in your case, on GitHub. You do your work locally, then git push to remote.
First, local changes and commits
So the steps to get your code changes into the local repository are as follows:
Make changes in your working directory. This is most often writing some code.
Build a commit by staging changes. This is done using git add.
"Save" the commit you've built into the repository. This is done using git commit.
These steps take place **locally*. None of these steps have any affect on your GitHub repository.
Secondly, git push to the remote repository (in this case, your GitHub one).
To get your code from local to remote repositories, git push is used.
Check what remote repositories are known by your local repository: git remote -v.
If the GitHub repository is not shown, you'll need to add it: git remote add <NAME> <URL>.
Because you didn't git clone, the two repositories (local and remote) don't have any commits in common. That's ok; it just means git doesn't automatically know where to push your changes, so you'll have to specifiy: git push <NAME> master:master. That'll push your local master branch to the <NAME> master branch.