IOS blog project build – push project to GitHub for management

Time:2020-11-26

Microblog project is managed by GitHub, and the project files are pushed to GitHub to facilitate management and research

Note: follow the first and ninth steps below to push to the remote warehouse. First, the GIT tracking directory is set up locally, and then pushed to the remote code base https://github.com/xxx/xxx.git That’s fine.

1、 Create a local code base

1. We first need to tell git that this folder is the project we need to track. So we send this command to initialize a new local git repository and switch to the local project directory (the local project name is itcastweibo-v10)

CD / users / MAC / documents / learning area / IOS code / itcastweibo-v10

2. Git init initialization
Git will create a hidden folder called. Git in the itcastweibo-v10 folder, which is your local code base

git init

2、 Stage file

Now we need the GIT command. We need to load all the project files. send out:

git add .

The last “.” symbol means “all files, folders and subfolders.”. If we only want to add specific files to source code control, we can specify them:
git add my_file, my_other_file

3、 Submission of documents

Now, we want to submit the staged file. Read “add a point in time where your files are in a recoverable state.”. We always submit our files with meaningful comments describing their current state. I’ve always used “initial commit” as my first commit comment.

git commit -m "initial commit"

That’s it. Now you can roll back to this commit state at any time. If you need to check the status, submission, etc. of your current staged and unstaged files, you can ask git’s status:

git status

4、 Create branch

Branching is the act of creating a separate version of your code, independent of your main branch. By default, every time you submit a file to git, it is stored in the “master” branch.
Now let’s say that you want to add a feature to your project, but you want to be able to roll back to the current version in case something goes wrong, or you decide to give up the feature. This is when you create branches. Create and switch to your new branch at the same time, send:

git checkout -b new_feature

Or, you can create a branch and switch manually, like this:

git branch new_featuregit checkout new_feature

To see all the branches of your current project, send this:

git branch

Now you can do whatever you want on your project: at any time, you can go back to where you were before you created the branch. Note that you can have multiple branches at the same time, and you can even create another branch from one branch.

5、 Merge branches

When you are satisfied with your new feature, you want to add it to the trunk branch. When you are on your new feature branch, you first need to load (stage) and submit your file:

git add .git commit -m "adds my new feature"

Then you move to your main branch:

git checkout master

Merge like this:

git merge new_feature

At this point, your main branch and your new function branch will become the same.

6、 Discard branch

On the contrary, if you want to discard the changes you made in the branch, you first need to load your file and commit it in the branch:

git add .git commit -m "feature to be discarded"

Then you move to the main branch:

git checkout master

Now, your code is in the state before you created the branch.

7、 Delete a branch

If you want to merge your branches into the main branches, send from the master branches:

git branch -d new_feature

If the changes have been merged, it will only delete the branches. If the branches are not merged, you will get an error message. To delete an unmerged branch (usually a change you don’t want to keep), you need to send the same command with a capital D. Force the branch to be deleted. I don’t want it anyway :

git branch -D new_feature

8、 Roll back to previous commit state

At some point, you may want to go back to the previous version of the code. First, you need to find out which version you want to go back to. To see all completed submissions, send:

git log

This will output your submission history, like this:

commit ca82a6dff817ec66f44342007202690a93763949Author: your_username 

[email protected] .comDate: Mon Nov 4 12:52:11 2013 -0700 changes the frontpage layout
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7Author: your_username [email protected] .comDate: Mon Nov 4 11:40:33 2013 -0700 adds my new feature
commit a11bef06a3f659402fe7563abf99ad00de2209e6Author: your_username [email protected] .comDate: Mon Nov 4 10:37:28 2013 -0700 initial commit
If you want to go back to the “add my new feature” submission, simply check out with the submitted ID (I usually only use nine characters at the beginning of the ID)

git checkout 085bb3bcb

You can also check out to a new branch, like this:

git checkout -b my_previous_version 085bb3bcb

Just don’t be crazy! The more complex your branches are, the more difficult it is to determine what you are really doing.

Force rollback to the last commit version and synchronize to local

[email protected]:/var/www/blog# git reset --hard 4e0b01f241e44
HEAD is now at 4e0b01f add style.light.css
[email protected]:/var/www/blog# git push -f origin master
Username for 'https://git.coding.net': myname
Password for 'https://[email protected]':
Total 0 (delta 0), reused 0 (delta 0)
To https://git.coding.net/myname/blog.git
 + 3c7bc66...4e0b01f master -> master (forced update)
[email protected]:/var/www/blog# git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

9、 Push to remote code base

The first time you want to push a local repository to a remote repository, you need to add it to your project configuration.Do this:

git remote add origin [email protected]:your_username/hello_ios.git

Note that the “origin” here is just a habit. It’s an alias for your remote code base, but you can use any other word you like. You can even have multiple remote repositories, and you just need to give them different aliases.
After that, you want to push the trunk branch of your local code base to your remote code base:

git push origin master

If you use bitbucket, you will be asked to enter your password. If you do, your local code base will be pushed to your remote code base.

Get a local copy of the remote code base

If you don’t have a local version of the remote code base (for example, if you start working on another machine that hasn’t used the project yet), you need to clone it first. Go to the folder your code base wants to copy to and send:
git clone https://[email protected]
On the other hand, if you are already working on a local project and just want to get the latest version from the remote code base, move it to the root directory of the project, and send:

git pull origin master

10、 Alias

Git allows you to create shortcuts (aliases) for commands you use frequently. For example, if you don’t want to enter git commit – M “some comment” every time, but instead enter git C “some comment”, you can add an alias to your git global configuration to achieve this, as follows:

git config --global alias.c 'commit -m'

This is a list of aliases I use:
git config –global alias.c ‘commit -m’
git config –global alias.co ‘checkout’
git config –global alias.cob ‘checkout -b’
git config –global alias.br ‘branch’
git config –global alias.m ‘merge’
git config –global alias.a ‘add .’
git config –global alias.s ‘status’
git config –global alias.dbr ‘branch -d’

We can add a personal repository repository in Xcode – “preference, and we can use Xcode to push updated projects in the future, instead of using commands to submit on the client side, which greatly improves the development efficiency.
IOS blog project build - push project to GitHub for management

11、 Handling server side and local code conflicts

For example, when the code in GitHub is changed, an error will be reported if the local code needs to be pushed to the GitHub repository. Because the version in the GitHub repository is newer than the local version, we need to pull the code from the local repository to the local, get the latest version, and then push it to the remote repository.

Git command

Macdemacbook-pro-3: ~ MaC $CD / users / MAC / documents / learning area / IOS code / itcastweibo-v10
MacdeMacBook-Pro-3:ItcastWeibo-v10 mac$ git pull origin master
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/corwien/SinaWeibo
 * branch            master     -> FETCH_HEAD
   34ef98b..d408ada  master     -> origin/master
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
MacdeMacBook-Pro-3:ItcastWeibo-v10 mac$

12、 Git command overview

IOS blog project build - push project to GitHub for management

Git overview map address

Take a look at my personal microblog: corwien personal blog