push changes to github using batch file with username and password - batch-file

I have the following running in a batch file
cd c:/dirtogithubrepo
git config --global user.name "my name"
git config --global user.email "myemail#mydomain.com"
git init
git status
git add data.js
git commit -m "Add data.js"
git remote -v
git push
pause
which does push the file up to git hub. my problem is that it asks me for my username and password every time it runs. Is there a way to add these in the process? or can anyone think of a work around
thanks

You should be using an SSH key to connect to your repository, this allows for you to not have to use a password - please see here for instructions
The basic steps are to:
Generate your Keys
Upload your Public Key to Github (Settings > SSH Keys)
Set up Git to use these keys
The link above talks you through this!

Related

How to enable that terminal reads from stdin [duplicate]

I have written scripts for Windows and Linux to essentially set up a new users workspace with all the git repositories from our server.
I would like the user to enter the password for our server once, store it in a local variable, pass that variable to each git pull command, then erase the password variable and exit.
How can I input the password when the git pull command requests it? Both for Windows batch file and a Linux shell script.
Here is code from the Linux script:
#!/bin/bash
echo "Enter password: "
read pswd
clear #No screen peaking
#This is repeated for each repo
location=folderName
mkdir $location
cd $location
git init
git remote add origin git#<server>:$location.git
git pull origin master
#Above prompts for password & is where I want to automatically input $pswd
I've tried various things recommended on SO and elsewhere, such as piping, reading from .txt file, etc. I would prefer to not need anything more than plain old windows cmd and Linux terminal commands. And as this script is just for set up purposes, I do not need to securely store the password permanently with something like ssh agent.
I'm running Windows 7 and Ubuntu 12.10, but this script is meant for setting up new users, so it should ideally work on most distributions.
Synopsis:
git pull "https://<username>:<password>#github.com/<github_account>/<repository_name>.git" <branch_name>
Example:
git pull "https://admin:12345#github.com/Jet/myProject.git" master
Note: This works for me on a bash script
I would really recommend to not try and manage that password step, and delegate that (both on Linux and Windows) to git credential helper.
See:
"Git http - securely remember credentials"
"How to use git with gnome-keyring integration"
The user will enter the password only once per session.
Read the remote url from git and then insert the ID and password (PW) to the url might work.
For example try the following:
cd ${REPOSITORY_DIR}
origin=$(git remote get-url origin)
origin_with_pass=${origin/"//"/"//${USER_ID}:${USER_PW}#"}
git pull ${origin_with_pass} master

Can not deploy create-react-app with token

I have been trying to deploy create-react-app, but got an error
fatal: repository 'https://github.com/charyyev2000/Portfolio-React.git/' not found
then I created a token and tried to deploy with that,
git remote add origin https://<TOKEN>#github.com/charyyev2000/Portfolio-React.git
again got an error;
Deleted repository, created again and tried to deploy, again got the same error
fatal: repository 'https://github.com/charyyev2000/Portfolio-React.git/' not found
What did I do wrong? or, is there something wrong with my homepage in packages.json?
"homepage": "https://charyyev2000.github.io/Portfolio-React",
I cant deploy from any other of my repositories too.
What should I do now.
You are new comer in Git/GitHub tools, I hope you can done this task.
Your remote repository URL is https://github.com/charyyev2000/Portfolio-React
Solution 1:
Create a new repository on the command line
echo "# Portfolio-React" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/charyyev2000/Portfolio-React.git
git push -u origin main
Solution 2: (I think you will prefer this solution, because your source code is exist).
Push an existing repository from the command line
git remote add origin https://github.com/charyyev2000/Portfolio-React.git
git branch -M main
git push -u origin main
Let's follow the guide what you see likes this
P/S: Sometime, you need
git add .
git commit -m"foo"
git push -v
or you see any guide on your console screen, let's follow guide what you see.
Your repository is probably private.
Try this: git remote set-url origin https://YOUR_GITHUB_USER#github.com/charyyev2000/Portfolio-React.git
Or use an ssh key.
https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent&ved=2ahUKEwjoysreiIjzAhVwTTABHQPHDzIQFnoECGwQAQ&sqi=2&usg=AOvVaw2B_nuIizqk0LtbV4qWtzzH

Why didn't the client folder from my project get uploaded on gitHub?

I wanted to upload a project on github repository so I can send it to my instructor and it’s my first time. All the folders’ content got uploaded except client folder and its icon looks different. Why did that happen?
I used these commands in the terminal
$ git add .
$ git commit -m "First commit"
$ git remote add origin remote repository URL
$ git remote -v
$ git push -u origin master
Edit: my client folder is a reactjs app
You would have to be a bit more specific.
One possible answer: There is a .gitignore file (hidden file) that prevents the client folder from being pushed.
Another: You simply didn't stage the client folder. Try git add ./client and then commit and push again.
In my case, Gatsby had created a .git folder in client which prevented it from being added to the repo.
rm -rf client/.git
After doing git add . check if the files are staged inside the client folder by doing git status.It may be the problem of .gitignore file which ignores specific files that are not to be committed. If client is not on .gitignore the files inside it should be staged. And if it is not staged after doing git add . you can see the individual files that are not staged after doing git status and individually add the files to staging area.

Escape the colon from a command so it's not render like a label in batch files

I'll make a bat file with goes deploy my site on GitHub pages. The repository is heinpauwelyn.github.io and is made with Angular-CLI. To deploy the site I could use this command:
ng github-pages:deploy
This will place everything on the gh-pages branch but it must stand on the master branch! I'm developing on the development branch.
To automate the proceedings of committing, deploying, checkout gh-pages, copy-pasting, checkout master, copy-pasting, committing and checkout development, I've create this bat file named deploy.bat:
git status
git add *
git commit -m "deploy"
git pull
git push
ng github-pages:deploy
git checkout gh-pages
echo "copy all your files in this folder to a temporary folder outside this repository (except these inside the `.gitignore` file)"
pause
rem must be automatic done by using this xcopy . ..\temp
git checkout master
echo "copy all your file form the temporary folder back into the repository"
pause
rem rmdir /s /q .
rem xcopy ..\temp .
git status
git add *
git commit -m "deploy"
git pull
git push
echo "site is deployed!"
git checkout development
The code will stop on this line: ng github-pages:deploy. I've checked the syntax on Wikipedia and have seen that the colon is a label to skip code from a running batch file. I think this colon gives the bug.
My question is now can I escape the colon from the batch file so that it's not longer a label but a command?
Note
The goal of the batch file is that I just must use one command to deploy my full site. In the package.json file of my project, I use this code:
{
"scripts": {
"deploy": "deploy.bat"
}
}
When the bug will be solved, I just use command below to deploy my site on the master branch.
npm run deploy
It wasn't the colon that gives the bug but because ng is a batch file. Helped answer: Azure Function / Azure Website Custom Deploy Script Ending Prematurely.
After searching and asking this question, I've found the solution that works!
git status
git add *
git commit -m "deploy"
git pull
git push
call ng.cmd "github-pages:deploy"
call git checkout master
call git merge origin/gh-pages --allow-unrelated-histories
dployer.exe rem | This is a little executable file I've written (it's just for changing
rem | content of some files)
git add *
git commit -m "deploy bug oke"
git pull
git push
git checkout development
Thanks to #MCND, #Mofi and #SomethingDark for the comments 😃!

Push changes to bitbucket using atom

I am using the text editor Atom and it should be possible to upload directly to bitbucket from atom. I found a thread here on stackoverflow someone asked for this and someone recommended git-plus package. I did download this package but it tells me i need to edit user.email and user.name variable in gitconfig file. But it doesnt say anywhere where i can find this gitconfig file. I found a few config files but none of them have these variables. Is this gitconfig file in my .git folder in my project or is it somewhere in atom? I hope someone here can help me with this
Set up git in your shell to use bitbucket as the remote repo.
You will first need to sort that basic Git config thing about the emails:
$ git config --global --get user.name
Your Name Here
$ git config --global --get user.email
your_email#someplace.com
If you don't have these values already added, then simply add them. Put your current directory someplace under the root of your atom repository (or, if you want to use the --global parameters [recommended]), then anywhere will do, really so long as it's your login you're working with.)
$ git config [--global] user.name "Your Name"
$ git config [--global] user.email "your_email#somplace.com"
First set up your ssh key so you don't have to type your password on every command. Once that's done, then go to the Git repo you set up for your Atom project. Most likely that's in the top level of my project. Go there and...
$ git remote -v
$ git remote add origin git#bitbucket.org:youruid/yourrepo.git
Now try it from the shell to make sure all is working:
$ git push
It's very likely you'll get a message similar to:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
Follow the advice given, then, if you're feeling particularly paranoid, make a change to any file in the repo -- using atom if you like, doesn't matter -- and try it all again:
$ git add -u
$ git commit [-v]
...
$ git push
This time, it should go off without a hitch.
Now back to atom...
If you've configured things there so that atom can access your Git repo locally, there should now be a Fetch widget in the lower right corner:
If you make a change now in atom, you'll see this change to Push... with the functionality to match.
The GitHub widget still doesn't do anything -- which is mildly annoying -- but I believe you might be able to find an atom package out there that does similar things.

Resources