search

Home  >  Q&A  >  body text

git - How to synchronize code across multiple computers

I am currently writing code on my desktop and laptop. I want to synchronize the code on the two machines. Can this be achieved through github? What are the steps?
I am a novice, the question may be a bit confusing, please give me some advice.

仅有的幸福仅有的幸福2767 days ago1226

reply all(4)I'll reply

  • 習慣沉默

    習慣沉默2017-05-02 09:47:06

    It can be achieved. Using GitHub Desktop is very convenient. Just learn how to use git. If you don't want to make the code public, you can apply for a domestic git platform, and you can use a private one for free. Github is open source by default and can be downloaded by others. The other is to build your own server. If you want it to be more powerful, similar to the web side of github, you can use Docker to build gitlab. It is very convenient, just one command. In addition, as a client, GitHub Desktop can operate other git projects by opening it locally. Graphical management and diff are very convenient.

    1. Build a warehouse.
    2. Set .gitignore to exclude things that you don’t want version control, such as some temporary log files.
    3. Submit it to the warehouse.
    4. Clone computer 2 locally, modify the code, and submit it to the warehouse
    5. Switch computer 1, pull the synchronization first, and synchronize the code submitted by computer 2.

    It is very convenient to use the GitHub Desktop graphical client for operations such as daily submissions, synchronous pulls, and pushes.
    You can first open an account with github, build a test warehouse, download GitHub Desktop to test it, run it through, and you will understand.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:47:06

    If you want to use github as your remote code hosting warehouse, I always think it is better to use git. After all, although the graphical github desktop tool is easy to use, its functions are simple, and you may also encounter Chinese garbled characters or push. The situation of not going up. So I think whether you are a novice or an expert, I think git should be the first choice. If you keep using github desktop, your git level may always stay at the graphical interface.
    For the landlord’s needs, the steps are as follows:

    1. Just like you usually write code, first create a project, such as creating a qt project or a vs project;

    2. Enter the project folder and run the following command to create a git repository:

    git init

    3. Then add the .gitignore file. You can refer to here for the function and creation method of this file.

    4. Add the current file to the staging area, where . represents all newly created or modified files

    git add .

    5. Submit this modification

    git commit -m "your commit message"

    6. Create a remote warehouse and open the github homepage to create a new warehouse. Note that it is best not to initialize and add any files to the warehouse, otherwise you will encounter trouble later.

    7. Add a link to the remote warehouse

    git remote add origin <url of your remote repository>

    8. Push to remote warehouse

    git push

    Now you can check whether the push is successful in the remote warehouse.

    If you are on another computer, you can clone the remote repository locally,

    git clone <url of your remote repository>

    Then use steps 4, 5, and 8 above to push the modifications of this computer to the remote warehouse.
    If you decide to use git, it is recommended to study the workflow of git in depth. I recommend the book progit. There is a free electronic version on the official website.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-02 09:47:06

    GitHub tutorial link

    reply
    0
  • ringa_lee

    ringa_lee2017-05-02 09:47:06

    Use git to build your own warehouse, either SVN or git.

    reply
    0
  • Cancelreply