Why can't I access my Github repo from CLI - github

I created a repo on Github, and I was able to commit code scripts to the repo from the Git Bash cli. Now, I have entered the master of my repo from the cli with cd reponame, but I can't commit new files to my Github repo of the same name. I can stage and add, but the command git commit -m "message" says my code is committed but when I go and refresh the repo on Github, there is no sign of the file. It didn't behave like this when I first setup the repo. Please, is there something I am not getting right?

after committing use git push so ur changes go to github and can be seen

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.

How to open a pull request on github for an improvement in a bitbucket fork?

I cloned a github repository into our Bitbucket account. Similar to https://gist.github.com/sangeeths/9467061.
I fixed a bug in my repository located in bitbucket. I'd like to open a pull request on the original github repository that fixes the bug.
If my fork were located on github, I would simply follow these instructions, but since my fork is on bitbucket, I don't know where to start.
How can I open a pull request from my bitbucket repo to the original github repo ?
You can:
clone the original GitHub repository to a different folder
add your local BitBucket repo as a remote
fetch your fix branch (make sure you fix is done in its own branch, not master)
create a PR using the cli/cli GitHub command line interface gh pr create
That is:
git clone https://github.com/original/repo
cd repo
git remote add bb ../yourLocalBitbucket/repo
git fetch bb
git checkout bb/fix
gh pr create
The gh pr create command will do the work for you:
When the current branch isn’t fully pushed to a git remote, a prompt will ask where to push the branch and offer an option to fork the base repository.

How to delete specific commit histories in Github created via file upload?

I normally upload my files to Github repository through the web interface. I accidentally uploaded a file to Github repository recently and this file contains information which I don't want others to see. Now, this private info is permanently recorded in the commit history.
How can I delete this specific commit from Github?
EDIT: The commit history was created through the file upload website of github. It was not created using git.
I will answer my own question. Credit goes to sasha-dev for his comment.
Here is what I did.
Use Github desktop to clone the github repostitory.
Launch command-line prompt. Go to the repository folder. Run the
following command;
git reset --hard HEAD~1 # remove last commit
Or the goal is to remove a specific commit, find out the commit hash
git reset --hard <commit hash>~
Next step is to force push the locally made changes to the remote github repository. Run this command;
git push -f
Commits will be removed from github repository at this point.

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

Fork from a branch in github

Is there a way to fork from a specific branch on GitHub? … For example, moodle has many branches (1.9, 2.0 … and so on). Can a clone be performed of just branch 1.9 and not the master branch always? Is it possible to clone a specific branch onto my PC?
I don’t know a native way yet, but you can do it following this recipe:
Fork the repository in question (called ‘upstream’) on the GitHub website to your workspace there.
Run the GitHub desktop application and clone the repository onto your PC.
Use the GitHub desktop application to open a shell in the repository. (The git commands are not available from the default PowerShell unless you configure that manually.)
Set the source repository as upstream:
git remote add upstream https://github.com/{user}/{source-repo}.git
Fetch the full upstream repository. (Right now, you only have a copy of its master branch.)
git fetch upstream
Make your file system copy the branch you want and give it any name:
git checkout upstream/{branch-in-question}
git checkout -b temporary
Publish your repo using the GitHub desktop application.
On the GitHub website, open your repository and click ‘settings’.
Change the “Default branch” to ‘temporary’. (Just change the drop-down menu, you don’t need to click the “Rename” button.)
Go back to your repository, go to the ‘branches’ tab, now you can delete the “master” branch.
Delete the master branch on your shell and make a new master branch:
git branch -d master
git branch master
git checkout master
git -d temporary
Once more, publish your repo using the GitHub desktop application.
On the GitHub website, open your repository and click ‘settings’.
Change the “Default branch” back to the (new) ‘master’ branch.
Go back to your repository, go to the ‘branches’ tab, now you can delete the “temporary” branch.
This should be what you were looking for. Perhaps GitHub will provide a more convenient way to do this in future (e.g., clicking “Fork” from a project’s branch results in exactly this behaviour).
Cloning means that you create a copy of the whole repository in your account including all branches and tags. However you are free to switch and track branches however you like.
No command line needed. Just create a new branch in your forked repository in GitHub. GitHub will ask you if you want to clone/mirror this new branch from the upstream repository. You can give any name to the new branch.
Yes, you can clone the single branch. For example, you have a branch named release1.0. If you would like to clone this branch into your pc then use the following line of code:
$ git clone git#bitbucket.org:git_username/git_repository_example -b release1.0 --single-branch
For those who don't like working with command-line. Here is a simple guide using the desktop client for GitHub:
Click the fork button of the repo on GitHub.com:
Make sure you have the desktop client installed
Click this button:
Clone the repo
In the desktop client, select the desired branch
Select the branch you'd like to work on and you're done
I'm posting here the method I've used.
Like the OP I wanted to only copy/fork one branch. But couldn't find an easy way.
in your repo create a new branch. It doesn't need to have the same name as the branch you want to fork
once created, verify that it is the selected branch, and click "Compare"
reverse the order of comparison (I have a userscript for that, see my profile if it's something you want to test).
the "base" repository must be yours, with the branch you've created
the "head" repository is the original, and the branch is the branch you want to fork
hit "create pull request" and continue until the PR is applied
That's it. You have the branch forked.
I'm using bitbucket but I'm sure this would work for GitHub as well.
Create a new repository
Checkout the branch using GitExtensions
Click Push to open the Push dialog
Set the destination URL to the new repository
Set the destination branch to "master"
Push
Your new repository will have the full history of the one branch only (not all branches like forking will have).
A fast, alternative approach is to create your own new repo.
Go to https://github.com/new and make a new repo. Do not initialize with README.
Scroll down to get your git remote
Then:
git remote rm origin
git config master.remote origin
git config master.merge refs/heads/master
// Run code from above image
git push --set-upstream origin yourbranchname
You will have a new repo with the original repo's code and a branch that can be made into a pull request.
SOLUTION:
For remote repository on GitHub and local repository
After fork all branches to your GitHub repository, you can delete Redundant branches in your GitHub repository.
And then you can only clone the branches you need to local.
Step One
Step Two
Only For local repository
git clone -b <branch name> --single-branch <repository>
If you want to further save your disk space, you can clone remote repository without history:
git clone -b <branch name> --depth 1 <repository>
notice: --depth implies --single-branch unless --no-single-branch is given.
https://git-scm.com/docs/git-clone
Switch to the branch you need in source repo
Click "Fork". You'll get forked master and the branch you're in.
I don't know how it works with more branches, but for my needs worked pretty well.