March 31, 2021

How to Commit code to Git / Bitbucket from Android Studio

                             On this blog I am going to explain how to commit the code to a git or bitbucket repository from android studio.  I already created a got repository on bitbucket, Here I will show how to commit and push the code to the repository I created on bitbucket.

I am doing this using the command on Android studio Terminal,

Step 1

First we need to initialize the git on out code, 

git init

         This command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.

Step 2

Adding a remote git repository, 

git remote add origin YOUR_GIT_REPOSITORY_HTTPS_LINK

          To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A remote name, for example, origin.

Step 3

Adding the files or changes to the repository, 

git add --all

         If this code is not working with you you can try the below code also, 

git add -A

         If you are in any subdirectory of the working directory, git add -A will add all files from the entire working directory, and git add . will add files from your current directory.

git add .

         If you are in any subdirectory of the working directory, git add .  will add new files and modifications, without deletions (on the current directory and its subdirectories).

git add -u

         If you are in any subdirectory of the working directory, git add -u will add stages modifications and deletions, without new files.

Step 4

Moves changes from the working directory to the local repository

git commit -m "YOUR_COMMIT_MESSAGE"

      This command takes the staged snapshot and commits it to the project history. My passing the Message you can Identify the changes we made on that commit.

Step 5

Upload local repository content to a remote repository, 

git push origin master --force

      This command  is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repository.

--force This option overrides the “fast forward” restriction and matches our local branch to the remote branch.

No comments:

Post a Comment