How to create Github Repository from Linux or Mac terminal? Easy Steps.

 Follow the steps the red codes are commands that you should run and blue codes are the outputs : 

1.  First go to the top level folder of you AndroidStudioProject

[niranjankhatri@localhost ~]$ ls
Android  android-studio  AndroidStudioProjects  Desktop  Documents  Downloads  Flutter  Music  photorec.se2  Pictures  Public  stale_outputs_checked  su  Templates  Videos
[niranjankhatri@localhost ~]$ cd AndroidStudioProjects
[niranjankhatri@localhost AndroidStudioProjects]$ ls
MyApplication 
[niranjankhatri@localhost AndroidStudioProjects]$ cd MyApplication
[niranjankhatri@localhost MyApplication]$ ls
app  build  build.gradle  gradle  gradle.properties  gradlew  gradlew.bat  local.properties  MyApplication.iml  README.md  settings.gradle



2. Initialize the git

[niranjankhatri@localhost MyApplication]$ git init
Initialized empty Git repository in /home/niranjankhatri/AndroidStudioProjects/MyApplication/.git/

3. List the current files and folders 

[niranjankhatri@localhost MyApplication]$ ls -latr
total 52
-rw-rw-r--. 1 niranjankhatri niranjankhatri  662 Mar 12 18:49 build.gradle
-rw-rw-r--. 1 niranjankhatri niranjankhatri  208 Mar 12 18:49 .gitignore
-rw-rw-r--. 1 niranjankhatri niranjankhatri 1169 Mar 12 18:49 gradle.properties
drwxrwxr-x. 3 niranjankhatri niranjankhatri 4096 Mar 12 18:49 gradle
-rwxrw-r--. 1 niranjankhatri niranjankhatri 5296 Mar 12 18:49 gradlew
-rw-rw-r--. 1 niranjankhatri niranjankhatri 2260 Mar 12 18:49 gradlew.bat
-rw-rw-r--. 1 niranjankhatri niranjankhatri  434 Mar 12 18:49 local.properties
-rw-rw-r--. 1 niranjankhatri niranjankhatri   49 Mar 12 18:49 settings.gradle
drwxrwxr-x. 4 niranjankhatri niranjankhatri 4096 Mar 12 18:49 app
drwxrwxr-x. 7 niranjankhatri niranjankhatri 4096 Apr  7 22:33 ..
drwxrwxr-x. 5 niranjankhatri niranjankhatri 4096 Apr 20 22:35 .
drwxrwxr-x. 7 niranjankhatri niranjankhatri 4096 Apr 20 22:35 .git

4. Create a .gitignore file to avoid tracking the bin and target folders 

[niranjankhatri@localhost MyApplication]$ gedit .gitignore

[niranjankhatri@localhost MyApplication]$ open -a TextEdit .gitignore (Mac) 


5. In the file write :
/bin/
/target/ 
Then Save it 

6. Add all files and folders to create the repository to git. Now all the files are ready to be added to github repository. 

niranjankhatri@localhost MyApplication]$ git add . 
warning: CRLF will be replaced by LF in gradlew.bat.
The file will have its original line endings in your working directory

7. Let's check the status if the files and folders are ready to be added. 
This files are currently staged and ready to be added to master branch. 

[niranjankhatri@localhost MyApplication]$ git status 
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
new file:   .gitignore
new file:   app/.gitignore
new file:   app/build.gradle
new file:   app/proguard-rules.pro
new file:   app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt
new file:   app/src/main/AndroidManifest.xml
new file:   app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file:   app/src/main/res/drawable/ic_launcher_background.xml
new file:   app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file:   app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file:   app/src/main/res/mipmap-hdpi/ic_launcher.png
new file:   app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file:   app/src/main/res/mipmap-mdpi/ic_launcher.png
new file:   app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file:   app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file:   app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file:   app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file:   app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file:   app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file:   app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file:   app/src/main/res/values/colors.xml
new file:   app/src/main/res/values/strings.xml
new file:   app/src/main/res/values/styles.xml
new file:   app/src/test/java/com/example/myapplication/ExampleUnitTest.kt
new file:   build.gradle
new file:   gradle.properties
new file:   gradle/wrapper/gradle-wrapper.jar
new file:   gradle/wrapper/gradle-wrapper.properties
new file:   gradlew
new file:   gradlew.bat
new file:   settings.gradle


8. Add you configuration to github

[niranjankhatri@localhost MyApplication]$ git config --global user.name "yourgithubaccountusername"
[niranjankhatri@localhost MyApplication]$ git config --global user.email "yourgithubaccountemail"

9. Do your first commit 

[niranjankhatri@localhost MyApplication]$ git commit -m "First Commit"
[master (root-commit) e41ec7f] First Commit
 31 files changed, 576 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 app/.gitignore
 create mode 100644 app/build.gradle
 create mode 100644 app/proguard-rules.pro
 create mode 100644 app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt
 create mode 100644 app/src/main/AndroidManifest.xml
 create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml
 create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml
 create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
 create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
 create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png
 create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png
 create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png
 create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png
 create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png
 create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
 create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png
 create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
 create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
 create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
 create mode 100644 app/src/main/res/values/colors.xml
 create mode 100644 app/src/main/res/values/strings.xml
 create mode 100644 app/src/main/res/values/styles.xml
 create mode 100644 app/src/test/java/com/example/myapplication/ExampleUnitTest.kt
 create mode 100644 build.gradle
 create mode 100644 gradle.properties
 create mode 100644 gradle/wrapper/gradle-wrapper.jar
 create mode 100644 gradle/wrapper/gradle-wrapper.properties
 create mode 100755 gradlew
 create mode 100644 gradlew.bat
 create mode 100644 settings.gradle

10. Now sing up and sign in to GitHub 




11. Click + buton to Create a new repository in GitHub

Note: For flutter project don't initialize this repository with a README file to avoid the conflict on push



12. Add to your remote repository branch created in GitHub so you can push and pull.
[niranjankhatri@localhost MyApplication]$ git remote add origin https://github.com/niranjk/MyApplication-.git


13. First Pull to rebase your master branch

[niranjankhatri@localhost MyApplication]$ git pull --rebase origin master 
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 649 bytes | 14.00 KiB/s, done.
From https://github.com/niranjk/MyApplication-
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: First Commit

14. Finally push your commit to the master branch that you created in GitHub 

[niranjankhatri@localhost MyApplication]$ git push origin master 
Username for 'https://github.com': yourUsername 
Password for 'https://yourUsername@github.com': 
Enumerating objects: 58, done.
Counting objects: 100% (58/58), done.
Delta compression using up to 4 threads
Compressing objects: 100% (45/45), done.
Writing objects: 100% (57/57), 129.41 KiB | 12.94 MiB/s, done.
Total 57 (delta 0), reused 0 (delta 0)
To https://github.com/niranjk/MyApplication-.git
   fd552e1..6642581  master -> master


15. Finally to check the current commits we use this command in terminal 
[niranjankhatri@localhost MyApplication]$ git log 


Thank you. 

Post By : Niranjan Khatri 




Comments

Popular Posts