I want to sync my code to my github repo, so anytime I update my code it should be updated in the repo. Is there any proper and structured way of doing this.
So this is how I am doing it now
1
$ cd my-project
$ git init
$ git remote add origin GITHUB_URL
$ git pull origin master
$ git status
$ git add .
$ git commit -m "Init repo."
$ git push -u origin master
then just repeat following steps
$ git add .
$ git commit -m "Init repo."
$ git push -u origin master
Related
I have been going at the endlessly all semester. I was able to add project from my prior year in school but have been unable to push and new projects to my repository.
I have tried deleting my key credentials via my key access chain.
I have created a new GitHub account and tried using that one.
I have deleted repositories started from scratch over and over.
I have read question on question and tried following multiple different answers on here.
What I wouldn't give to understand what is going on and why nothing seems to allow me to push a project anymore.
The most current attempt was going back to my original GitHub account.
I created a brand new repository.
I created a new folder and copied my simple python project into it and saved.
error: remote origin already exists.
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote rm origin
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote rm upstream
error: No such remote: 'upstream'
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote add origin https://github.com/stephanieBrandon/GuessARandomNumberGame.git
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/stephanieBrandon/GuessARandomNumberGame.git'
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % ls -a
. .. guess_a_random_number.py
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /Users/stephaniebrandon/Documents/GitHubPortfolio/Python/GuessARandomNumberGame/pythonGame/.git/
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote add origin https://github.com/stephanieBrandon/GuessARandomNumberGame.git
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/stephanieBrandon/GuessARandomNumberGame.git'
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % ls -a
. .. .git guess_a_random_number.py
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git status
On branch master
I am hoping there is just some simple thing I am missing, if someone could explain and help me out it would be much appreciated.
Stephanie, your local branch name is "master", not "main" as you can see from the "git status" output.
If you try "git push origin master", it should work.
You dont have branch main, you have branch master. 😊
Try:
git push origin master
You need to have some commits before pushing your repository to Github.
Moreover, your local default branch name is master, so you have to use git push -u origin master instead of git push -u origin main
$ ls
guess_a_random_number.py
$ git init
Initialized empty Git repository in /Users/stephaniebrandon/Documents/GitHubPortfolio/Python/GuessARandomNumberGame/pythonGame/.git/
$ git add .
$ git commit -m "initial commit"
$ git remote add origin https://github.com/stephanieBrandon/GuessARandomNumberGame.git
$ git push -u origin master # not main
I have installed the git ,created repository , then I have tried to push from vs code to github repository with cmd
git push -u origin main
Git say error: failed to push some refs to 'github.com:loobj126/boredape-dapp-bj.git''
What's the problem?
https://github.com/loobj126/boredape-dapp-bj
i ve few approach yet still not resolve
https://komodor.com/learn/how-to-fix-failed-to-push-some-refs-to-git-errors/
Latest input :
after initialize
[2022-04-20T08:44:06.669Z] Validating found git in: C:\Program Files\Git\cmd\git.exe
[2022-04-20T08:44:06.796Z] Using git 2.35.3.windows.1 from C:\Program Files\Git\cmd\git.exe
[2022-04-20T10:45:43.723Z] > git init [128ms]
[2022-04-20T10:45:44.399Z] > git rev-parse --git-dir [72ms]
[2022-04-20T10:45:44.403Z] Open repository: c:\Users\loobj\boredape-dapp-bj
[2022-04-20T10:45:44.606Z] > git fetch [197ms]
[2022-04-20T10:45:44.676Z] > git symbolic-ref --short HEAD [119ms]
[2022-04-20T10:45:44.765Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [85ms]
[2022-04-20T10:45:44.872Z] > git remote --verbose [99ms]
[2022-04-20T10:45:44.888Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [119ms]
[2022-04-20T10:45:45.019Z] > git config --get commit.template [122ms]
[2022-04-20T10:45:45.040Z] > git config --local branch.master.github-pr-owner-number [121ms]
[2022-04-20T10:45:45.300Z] > git symbolic-ref --short HEAD [101ms]
[2022-04-20T10:45:45.385Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [80ms]
[2022-04-20T10:45:45.490Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [101ms]
[2022-04-20T10:45:45.507Z] > git remote --verbose [115ms]
[2022-04-20T10:45:45.589Z] > git config --get commit.template [76ms]
Click push
[2022-04-20T10:59:18.763Z] > git push boredape-dapp-bj master [153ms]
[2022-04-20T10:59:18.763Z] error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/loobj126/boredape-dapp-bj.git'
[2022-04-20T11:00:41.028Z] > git fetch [141ms]
[2022-04-20T11:00:41.220Z] > git symbolic-ref --short HEAD [68ms]
[2022-04-20T11:00:41.286Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [63ms]
[2022-04-20T11:00:41.380Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [91ms]
[2022-04-20T11:00:41.394Z] > git remote --verbose [102ms]
[2022-04-20T11:00:41.485Z] > git config --get commit.template [84ms]
Solution 1: for error: src refspec master does not match any.
All you need to perform is git commit with a proper message and then do git push to the remote origin to avoid any errors.
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
git commit -m "initial commit"
git push origin master
Solution 2 – First, check what refs you have, and once you find that, make a git push to the specific remote branch.
# To get all the ref
git show-ref
# replace with your branch name according to ref
git push origin HEAD:<branch>
this worked for me.
To fix the error, go on and run following commands:
git pull --rebase origin main
git push -u origin main
If the first command above runs successfully, you should get a response that says: Successfully rebased and updated refs/heads/main.
The second command pushes your local repo's current state to the remote branch.
ref: https://www.freecodecamp.org/news/error-failed-to-push-some-refs-to-how-to-fix-in-git/
i am getting error sh.exe: notepad: command not found please short out my problem
Thanks
For the commit to GitHub part, you need to add (if you have created an empty yourRepo on GitHub):
git config user.name yourGitHubUsername
git config user.email yourGitHubEmail
git add .
git commit -m "First commit"
git remote add origin https://yourAccount#github.com/yourAccount/yourRepo
git push -u origin master
If that fails because GitHub already created one commit when you initialized your "empty" repo (it can add by default a README.md and a .gitignore), do a:
git pull --rebase origin master
git push -u origin master
If you really have to call notepad from a mingw session, you can use this wrapper:
#!/bin/sh
'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar \
-nosession -noPlugin "$(cygpath -w "$*")"
But remember you can use msysgit from a DOS session as well.
Seps:
1.git init
2. git status
3. git add .
4. git commit -a
5. git status
I am new to GitHub, but I have followed the steps to create a repo:
$ mkdir fb
$ cd fb
$ git init
$ git add README
$ git commit -m 'first commit'
$ git push origin master
Now when I try to make my first commit, I get the follwowing error:
$ git push origin master
error: Cannot access URL https://github.com/xxx/yyy/, return code 60
error: failed to push some refs to 'https://github.com/xxx/yyy'
I am using the latest git version. Why does GitHub throw this unusal error and how do I fix it?
What if you try using the SSH protocol for the git repository, e.g. git#github.com:xxx/yyy.git, and see if that works for you?
$ git remote rm origin
$ git remote add origin git#github.com:xxx/yyy.git
I believe that return error code has something to do with the SSL Certificate... I'm sorry I cannot help further.
How can I create a new repository from my machine using git bash?
I followed the below steps:
mkdir ~/Hello-World
cd ~/Hello-World
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin https://github.com/username/Hello-World.git
git push origin master
But I'm getting "Fatal error: did you run update-server-info on the server? "
You cannot create a repo on github using git bash. Git and github are different things. Github is a platform that let's you host and collaborate on code while git is the version control tool used. You can read more about them on wikipedia articles: github and git.
However if your intention is to create a github repo using terminal, you can do it using the github api and curl.
Probably the easiest way to create a repo on github is somewhere before this line:
git remote add origin https://github.com/username/Hello-World.git
go to https://github.com/new and create a repository on github, then run your last two lines and everything should work.
I have created this bash file to do it all automatically.
#!/bin/sh
reponame="$1"
if [ "$reponame" = "" ]; then
read -p "Enter Github Repository Name: " reponame
fi
mkdir ./$reponame
cd $reponame
curl -u USERNAME https://api.github.com/user/repos -d "{\"name\":\"$reponame\"}"
git init
echo "ADD README CONTENT" > README.md
git add README.md
git commit -m "Starting Out"
git remote add origin git#github.com:USERNAME/$reponame.git
git push -u origin master
So how:
copy the code above. save it as NAME.sh, add it to your PATH. restart terminal or open a new one.
$ NAME newreponame
$ NAME
$ Enter Github Repository Name:
Thanks.
First, try to do this right before the git push:
git pull repo branch
Then try to do the following:
$ git init --bare yourreponame.git
Then do what you were doing before:
touch README
git add README
git commit -m 'first commit'
git remote add origin https://github.com/username/Hello-World.git
git push origin master
I think it is doable.
You can do it using curl (if you are on Windows, you'll have to install it)
curl -u USER https://api.github.com/user/repos -d '{ "name": "REPO" }'
Make sure to replace USER and REPO with your github username and the name of the repository you want to create respectively
It asks for password, input your github admin password and you are good to go.
Actually answered by James Barnett here https://teamtreehouse.com/community/how-does-one-add-a-repository-to-github-using-git-commandline-calls-only
Overview
Command 'git' do not allow you to create repo but it's possible to create new repo at github from BASH script. All solutions use user/password authentication which is deplicated but stil in use. Authentication must be done using personal access token.
Below there are solutions:
3rd party application
https://github.com/github/hub
sudo apt install hub;
cd <folder with code>;
hub init;
hub create -p -d "<repo description>" -h "<project site>" \
"user_name>/<repo_name>";
More options: https://hub.github.com/hub-create.1.html
Pure BASH
REPONAME="TEST";
DOMAIN="www.example.com";
DESCRIPTION="Repo Description";
GITHUB_USER="github_user";
FOLDER="$HOME/temp/$REPONAME";
mkdir -p "$FOLDER"; cd "$FOLDER";
read -r -d '' JSON_TEMPLATE << EOF
{
"name" : "%s",
"description" : "%s",
"homepage" : "%s",
"visibility" : "private",
"private" : true,
"has_issues" : false,
"has_downloads" : false,
"has_wiki" : false,
"has_projects" : false
}
EOF
JSON_OUTPUT=$(printf "$JSON_TEMPLATE" "$REPO_NAME" \
"$DESCRIPTION" "http://$DOMAIN");
# https://developer.github.com/v3/repos/#create-an-organization-repository
curl -u ${GITHUB_USER} https://api.github.com/user/repos \
-d "$JSON_OUTPUT"
just try to add -u in your last line:
git push -u origin master
Maybe you are getting this error because you didn't set your identity:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe#example.com
Here you can find the steps to create and put your repository on github:
http://programertools.blogspot.com/2014/04/how-to-use-github.html