Fundamentals 10 min read

Essential Git Tips and Commands After One Year of Use

This article shares a comprehensive one‑year‑long Git usage summary, covering essential commands for configuration, SSH key management, remote URL changes, viewing history, handling push errors, submodule operations, branch management, conflict resolution, and best practices for committing and reverting code.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Essential Git Tips and Commands After One Year of Use

After using Git for a year, I compiled a practical summary that covers most everyday scenarios and helps you work more efficiently.

Configure Git user name and email

git config --global user.name "xxx"
git config --global user.email "[email protected]"

View current configuration:

git config --list

Generate and use an SSH key

Check for an existing key: cd ~/.ssh If none exists, generate a new one: ssh-keygen -t rsa -C "[email protected]" Press Enter three times to accept defaults; you will obtain id_rsa and id_rsa.pub. Do not modify the keys after creation.

Change remote repository URL

git remote set-url origin [email protected]:res_dev_group/test.git
git remote -v

View file modification history

Show concise log for a file: git log --pretty=oneline <filename> Inspect a specific commit:

git show 356f6def9d3fb7f3b9032ff5aa4b9110d4cca87e

Fix push default warning

Git 1.x defaults to matching, while Git 2.x defaults to simple. To use the older behavior:

git config --global push.default matching

Use submodules for shared code

Add a submodule: git submodule add <repo_url> <path> Remove a submodule (edit .gitmodules then run): git rm --cached <submodule_path> Initialize submodules after cloning:

git submodule update --init --recursive

Cancel a staged file

git reset HEAD <file>...

Delete files

Remove from index and filesystem:

git rm file1
git commit

Remove only from index (keep in filesystem):

git rm --cached file1
git commit

Rollback to a previous commit

git reset --hard 248cba8e77231601d1189e3576dc096c8986ae51

Pull again if you need to revert the rollback.

Compare historical versions

git log
git show 4ebd4bbc3ed321d01484a4ed206f18ce2ebde5ca
git diff c0f28a2ec490236caa13dec0e8ea826583b49b7a 2e476412c34a63b213b735e5a6d90cd05b014c33

Branch management

git checkout -b new_branch
git branch
git checkout master
git merge new_branch
git branch -d new_branch

Resolve merge conflicts

Conflict markers look like:

a123
<<<<<<< HEAD
b789
=======
b45678910
>>>>>>> 6853e5ff961e684d3a6c02d4d06183b5ff330dcc
c

Keep your changes (between <<<<<<< HEAD and =======) and the incoming changes (between ======= and >>>>>>>), then commit.

Typical push failure and recovery

If git push fails because the remote has newer commits, first pull: git pull Resolve any conflicts, then repeat the usual workflow:

git add ...
git commit -m "..."
git push

Successful commit workflow

git status
git diff
git add dirname1/filename1.py dirname2/filenam2.py
git commit -m "fixed: modify upload logic"
git push

Understanding GitHub Pull Requests

Fork the original repository (Repo A) to your account (Repo A2), work on A2, then create a Pull Request on GitHub to ask the owner of Repo A to merge your changes.

Common error handling

Pathspec not found

git checkout master
git pull
git checkout new_branch

Large file push errors (HTTP 411/413)

Increase the HTTP post buffer size: git config http.postBuffer 524288000 If the error persists, ensure your SSH key is correctly added to the remote repository and retry the push.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

conflict resolutionsubmodulebranching
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.