Thursday, June 11, 2020

Initializing git repo and setting remote

I have been creating a lot of git repos recently. I am tired of looking up the same information again and again.

I have been creating a lot of Java projects as I experiment with Spring Boot. After creating a repo, I experiment with it a bit, then decide if I want to keep working in it.

The first step is to change to the project directory and and a .gitignore file. I have been using Java on a Mac and this is the file I use.

HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/

### VS Code ###
.vscode/
 
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Mac OS $
.DS_Store


Execute git init in the project folder. This creates the .git folder that is the local repo.

I am using GitHub to store remote copies of the repo. Create a new, empty repo and issue the commands:

git commit -m "first commit"
git remote add origin https://git-username@github.com/git-username/git-repo.git
git push -u origin master
 
After these commands, I can use git push to commit changes.

No comments:

Post a Comment

Followers