Java SE: Project push GitHub

Java Fundamentals

javase
git
github
project
cloud
Sync maven project to github cloud
Author

albertprofe

Published

Tuesday, June 1, 2021

Modified

Saturday, September 7, 2024

1 Maven Project push to GitHub: CLI gh & clone

To connect a local project on IntelliJ IDEA to GitHub.com, you will need to create a repository on GitHub and then push your local project to the repository. Here’s a step-by-step guide:

From CLI gh:

  1. Go to browser and create an account on GitHub.com
  2. Open on your terminal and install git: install git
  3. Open your terminal and install cli gh: install CLI gh and log in to GitHub.com
  4. Create repository on GitHub.com: Create a repo
  5. At the top of your GitHub repository’s Quick Setup page, click the clipboard icon to copy clone GitHub CLI: gh repo clone AlbertProfe/wiki. This will initialize the local directory as a Git repository with a copy of remote repository.
  6. Create Maven Project within that directory/repository local git: create Maven Project
  7. Upload/sync/push: git commit and push from CLI or from IntelliJ IDEA: Commit and push changes to Git repository

1.1 Screen-shoots step-by-step after installing git and github (2022-12-19)

First, install git and CLI gh and create a GitHub.con account.

Log in via CLI gh to GitHub.com, in this case using a browser where you are logged in GitHub.com

Log in via CLI gh to GitHub.com, in this case using a browser where you are logged in GitHub.com

Create a repo at GitHub.com: button new

Create a repo at GitHub.com: button new

Create a repo at GitHub.com: name and configuration

Create a repo at GitHub.com: name and configuration

Create a repo at GitHub.com: created

Create a repo at GitHub.com: created

Get the code to clone the repo: copy

Get the code to clone the repo: copy

Create/select a folder where the repo will be created

Create/select a folder where the repo will be created

Go to the terminal and paste it

Go to the terminal and paste it

Create maven project: create

Create maven project: create

Create maven project: created and structure checked

Create maven project: created and structure checked

Let’s add and commit this project

Let’s add and commit this project

8 added files

8 added files

Now it is time to commit, first write it

Now it is time to commit, first write it

Visual Code and git making the commit

Visual Code and git making the commit

Commit done, now, the push to remote repo

Commit done, now, the push to remote repo

After push button Visual Code demands confirmation

After push button Visual Code demands confirmation

Pushing …. and pushed

Pushing …. and pushed

Check GitHub.com repo has got the project pushed

Check GitHub.com repo has got the project pushed

2 Maven Project push to GitHub: from IntelliJ IDEA VCS

IntellJIdea Main Menu

IntellJIdea Main Menu

IntellJIdea Main Menu

IntellJIdea Main Menu
  1. Open your IntelliJ IDEA project.
  2. In the VCS menu, select the option to enable version control integration.
  3. Select Git as the version control system.
  4. Add the files in your new local repository. This stages them for the first commit.
  5. Commit the files that you’ve staged in your local repository.
  6. In the VCS menu, select the option to create a new repository.
  7. Choose the location for the repository and click the Create button.
  8. In the VCS menu, select the option to push changes.
  9. Enter your GitHub login credentials and click the Push button.

Now your local project is connected to the repository on GitHub and any changes you make locally will be reflected in the repository on GitHub.

3 Maven Project shortest way: from IntelliJ IDEA git init

  1. Version Control > Create Git Repository

Version Control > Create Git Repository

Version Control > Create Git Repository

Select local directory to git init

Select local directory to git init

Local Directory Maven Project

Local Directory Maven Project
  1. Create Remote Repo on GitHub.com and copy HHTPS direction

IntellJIdea Main Menu

IntellJIdea Main Menu

copy HHTPS direction 1/2

copy HHTPS direction 1/2

copy HHTPS direction 2/2

copy HHTPS direction 2/2
  1. Commit and Push and when IntellJIdea ask for Remote Repo Direcion paste it

Select all files: git add. and Commit and push 1/2

Select all files: git add. and Commit and push 1/2

Commit and push 2/2

Commit and push 2/2

Push Command to MovieManager: master > define remote

Push Command to MovieManager: master > define remote

paste URL 1/2

paste URL 1/2

paste URL 2/2

paste URL 2/2

4 Maven Project push to GitHub: CLI git

Once the Maven Project Java SE is created, we are going to control its versions with git and upload to GitHub.com by CLI git/gh.

We need:

  • Github.com account created and logged in
  • git and gh installed
  • gh logged to GitHub.com
  • Maven Project Java SE created

The Maven Project Java SE Hello11 is already created and ready to work with git

The Maven Project Java SE Hello11 is already created and ready to work with git

Let’s create the git local repository with git init

Let’s create the git local repository with git init

Now this folder is git local repository

Now this folder is git local repository

Let’s identify the user, and then we track the files and commit them

Let’s identify the user, and then we track the files and commit them

With the gh CLI we create a remote repo called Hello11

With the gh CLI we create a remote repo called Hello11

Remote repository created

Remote repository created

Now it is time to add our remote repository Hello11 to our local repository. It will names as origin

Now it is time to add our remote repository Hello11 to our local repository. It will names as origin

Let’s push the project

Let’s push the project

Project pushed

Project pushed
Code bash linux git/gh

albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ 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 /home/albert/MyProjects/Sandbox/Hello11/.git/
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ git config user.name "albert"
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ git config user.email "albertprofe@gmail.com"
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ git add .
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ git commit -m "crete project"
[master (root-commit) 4cd7009] crete project
 7 files changed, 171 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .idea/.gitignore
 create mode 100644 .idea/encodings.xml
 create mode 100644 .idea/misc.xml
 create mode 100644 pom.xml
 create mode 100644 src/main/java/org/example/App.java
 create mode 100644 src/test/java/org/example/AppTest.java
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ gh repo create hello11 --public
 Created repository AlbertProfe/hello11 on GitHub
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ git remote add origin https://github.com/AlbertProfe/hello11.git
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$ git push -u origin master
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (19/19), 2.64 KiB | 675.00 KiB/s, done.
Total 19 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/AlbertProfe/hello11.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
albert@albert-VirtualBox:~/MyProjects/Sandbox/Hello11$