Git Useful Commands, and Tricks
Save GitHub credentials and automatically fill them in
Enterprises will require you to generate a GitHub token, and use that instead of a password when you clone or push to an enterprise GitHub repository. It's daunting to enter credentials manually. One way is to only save your token as an environment variable, and when git prompts you, call that env variable. But this is cumbersome and faulty. The better and more secure way is to have it filled in automatically, and here's how.
Add the following lines to your ~/.gitconfig
file. If you don't have it, create it.
Where ${USER}
and ${GIT_TOKEN}
are the environment variables where you saved your username and GitHub token.
If `git pull` or `git fetch` don't work
git pull and git fetch both download remote changes to local, git fetch suppose to overwrite local changes, I use this whenever I'm reviewing a repo, but don't want to change or contribute to it.
Suppose you fiddled with the local file to run, test, and try. Then you no longer need those changes, and want to pull down the new remote changes and overwrite/delete your local changes.
Sometimes it'll give you a strange error about the configuration manager, that you can't resolve following online tips to alias the config manager. The Abort error in git pull
will tell you to stash or committ your local changes. You don't care about those local changes anyway, just do git stash
then git stash drop
immediately after. Now you can git pull
without any issues.
Last updated