Git commands to keep a fork up to date

Phil Nash on August 20, 2018

I’ve seen the following tweet about git making its way around Twitter recently: Cory House 🏠 ... [Read Full]
markdown guide
 

Thanks for sharing Phil! I created an alias for rebasing my forks of upstream remotes, which is what I currently do when working on dev.to's codebase. gitaliases.iamdeveloper.com/#file-... if you're interested.

 

Ooh, a pull --rebase upstream master. Pro level upstream work!

I have shied away from too many aliases from my git setup, purely so that I can remember the actual commands and work with git anywhere. That's quite the list you have there and I bet I and others would learn quite a bit from reading through the ones you have aliased, which I assume you also use relatively frequently. Have you thought of writing anything up on all of these?

 

Another reason to shy away from aliases is that you get used to the aliases and then what happens when you use another system and forget you set up aliases ? Don’t laugh! It easily happens and although it’s never caused me a problem it’s because I don’t use aliases that have any behaviour modifications that matter; I for example alias gdb to ‘gdb -q’ but that’s harmless if it’s not on another install. Other commands can be far more devastating.

They can be useful but always always always remember this : aliases are for convenience and although I wouldn’t say it’s convenience XOR security the two do fight each other. And this includes data security too! But as pointed out if you rely too much on aliases you train your brain to remember those and forget the real invocations. This can particularly be a problem with different OSes more generally whether you go to a different job or maybe even worse is you use both on a daily basis.

Btw it’s happened that some people have gone to a new job but the previous say admin had set up aliases or config files that modify behaviour that has devastating consequences. This could even be deliberate and even compromise the network even installing a back door before parting! Yes that’s beyond development but still worth remembering.

 

I probably should. I mention it to others occasionally in comments. At the moment though, I've started, in my head at least, a "Converting dev.to's search to Preact", so gotta get that one out first 😉, i.e. github.com/thepracticaldev/dev.to/...

Keep up the awesome posts and looking forward to the next one. 🔥

 
 

Super useful post Phil, folks are going to love this one.

 

Thanks Ben! I'm mainly glad I managed to write something again, it's been too long!

 

It is probably worth to mention that all that is perfectly applicable to any clone of this repository, even if it’s stored on the roommate’s laptop, not in GH/GL/BB.

 

Ah, you mean for the case in which we use git in a truly distributed fashion, rather than the centralised way we've evolved with services like GitHub? I could, but I trust that anyone who knows what they're doing cloning aross local networks probably also knows how to add remotes, fetch and merge as well!

 

Or even private repos. I have quite a few on my server that are only accessible by ssh and I have ingress filtering - and don’t allow password logins either.

You shouldn’t assume that people know all the features even if they do know how to do something else. And even if they do know they might benefit from it or think of something new! That’s the beauty of the Unix philosophy and the pipe.

Yup, but this article had quite a narrow scope. I could have explained much, much more, but I wanted to keep the message tight.

 
 

Just a suggestion for the document itself and at the least future documents :

Add a prompt to the command invocation (that is prepend) to make it clearer what you type and what the output is. Maybe it’s because I am an old timer and also quite literal but my favourite example of that is quotes and a dot inside in say a VI editor tutorial i.e. ‘dd.’ which would repeat the action.

Anyway whether it’s a ‘>’ or a ‘$’ or if you want to go old school even a ‘%’ (brings back memories heh) it would make the article a bit clearer.

Cheers.

 

You know, I go and back and forward over this a bit.

I understand that the prompt gives a little more context, which is useful. However, I also know that people like to copy and paste from articles online (you can argue this is bad, but that's not my choice) and sometimes will copy the prompt as well and the command won't work.

I've even seen someone implement a $ function in their terminal that just passes through the arguments to run them so that they aren't caught out by the inclusion of a $ in online instructions (can't find the article about this right now, but I swear it exists).

For me right now, I like to make things copy-pastable without any surprises, so I'll keep the article as it is. I appreciate the feedback though, thank you.

 


git pull upstream master

works just fine in most of the scenarios.

 

That is correct and why I talked about using pull right near the end of the post. It’s nice to know how to use the other commands too though, which is why I wanted to explain them too.

 

Yes I read that too. You explained everything and it was good but in my opinion it was better to discuss pull first and explaining things further. BTW it's a great article.

Ah, cool, thanks. I thought it was better to build up from the basic components before unveiling the shortcuts. Thanks for reading!

Background is almost always better - but you could add a note at first that there’s a built in command that does both i.e. merges the two commands. And no I can’t help it. I love punning!

 

Awesome! I needed this info twice last week, and now I have a handy reference for all those cases in the future! Bravo!

 

If only I'd written it last week then! Hopefully it will help in the future though, I know I always end up checking back on my own blog posts to remind myself. So if it helps anyone else, that's even better.

 

And a big 🍻 for talking about fetch and merge before offering the pull shortcut. It's much more didactic.

 

Actually if the fork is solely used to make PRs you never have to push the ~master branch to the fork. Just don't forget to pull the origin before making a change a push the feature/fix branch on your fork... Although if you're a bit obsessional it's nice to have the GH message "this fork is even with its origin"

 

That may be true, but as it's only one extra command then why not do it? And I am that obsessed about the text on GitHub telling me it's up to date!

 

TIP

Also you can set default upstream for your push, by:
git push -u remote branch, i.e.: git push -u origin master.

So every next time, you have to push in short way git push.

 

That is true, though when you clone a repo the default upstream is normally set to origin master. This is useful if you want to work on a different remote branch.

When I push a branch that I want to make into a pull request, I normally do git push -u origin new-branch which allows me to easily make updates to that branch.

Thanks for adding the tip!

 

I don't think I could use git with those 6 commands anyway, because 'log' is so fundamental.

code of conduct - report abuse