Only One.Only One.Only One.

preface

One day, WHEN I received the request to change the version of my old project, I was rubbing my hands. My beloved Android happened to remember that a friend of mine asked me how to upload my local Android project to GitHub. It has been a long time, so I took this opportunity to play it again and take notes.

Upload, play ~

The following will gradually record the personal uploading habits of the way, there are good ways to welcome exchange ~

1. GitHub creates private repositories

This is optional, depending on the nature of the project to create a private or public repository.

Personal habit in this operation of the following two steps:

  • Select Initialize this repository with a README to Initialize the README file in the remote repository.

ReadMe file is mainly used to record information about the project, such as the use of tripartite libraries, record the updated version, etc., mainly for the convenience of friends who take over the back can quickly get started.

  • Select Add Android Ignore file.

During the Android compilation process, there will be some temporary files and local project corresponding localization configuration, etc. Everyone in the development team may have different environment. Try to avoid uploading meaningless content, such as your personal localization configuration.

2. Simple user rights management

Our development team usually consists of many people, so how can we ensure that others can access our private projects?

Very Easy ~

Click “Invite Teams or people” and type the name of the GitHub user you want to add in the pop-up box:

Assign different permissions for each partner’s work criticism, and make a case-by-case analysis:

After the completion of the lower click “agree to add so-and-so to this project warehouse”, then the following user group will appear just add children’s shoes personal information, but also need to agree to join the corresponding children’s shoes can, after all, strong twist melon is not sweet.

3. Rip Git and upload it to GitHub

Android Studio builds Android projects and then removes.gitignore’s default Git ignore files.

There are two reasons for deletion:

  • To create a remote repository, select Add Android Ignore file.
  • Just want to expand a little Git practical tips.

Here are the basic steps:

  1. To initialize Git, use the command line tool to go to the root directory of the Android project you are currently creating, or directly use the Terminal tool of Android Studio.
git init
Copy the code
  1. Add a local file to the staging area:
git add .
Copy the code
  1. To commit a local file to a remote library (just commit, not push up) :
git commit -m "Commit Info"
Copy the code

Here is the schematic diagram of personal operation, so that partners can view the operation more intuitively:

Then continue tearing Git by hand.

  1. Relationship a local project with a remote repository:
Git remote add originCopy the code
  1. Synchronize the remote repository code locally
Git pull --rebase originCopy the code

Here’s another operation diagram:

  1. Push local code to remote repository

Note here that since the remote library is pushed for the first time, the following command is used:

Git push -u originCopy the code

Subsequent pushes do not need to add the -u parameter:

Git push OriginCopy the code

To an operation diagram, strictly implement chicken boss intimate sharing ~

Refresh GitHub at this point, and the magical local code has been committed to the remote repository.

Extension – What if there are files not ignored after submission?

I don’t know if you noticed the two bright red arrows in the image above, but they’re not really useless. But we set the file to be ignored and added successfully. What about this situation?

1. Delete the local cache

git rm -r --cached .
Copy the code

2. Adjust ignored files

You can add files or directories to be ignored.

3. Add the changed file to the temporary storage area

git add .
Copy the code

4. Submit the remote repository

git commit -m 'Update info'
Copy the code

5. Push the remote repository

git push origin master
Copy the code

Refresh Github.

Thanks to my brother wen ~

The resources

  • GitHub.com/Use Git
  • Git Cheat Sheets
  • Git Documentation